Skip to main content
Version: v2 RC

Modify data: update()

Perform an UPDATE on the table or view.

By default, updated rows are not returned. To return it, chain the call with .select() after filters.

const { error } = await supabase
.from('countries')
.update({ name: 'Australia' })
.eq('id', 1)

Parameters

  • valuesrequiredRow

    The values to update with

  • optionsrequiredobject

    Named parameters

      Properties
    • countoptionalexact | planned | estimated

      Count algorithm to use to count updated rows.

      "exact": Exact but slow count algorithm. Performs a COUNT(*) under the hood.

      "planned": Approximated but fast count algorithm. Uses the Postgres statistics under the hood.

      "estimated": Uses exact count for low numbers and planned count for high numbers.

        Properties
      • estimatedrequiredliteral

        No description provided.

      • plannedrequiredliteral

        No description provided.

      • exactrequiredliteral

        No description provided.

Notes

  • update() should always be combined with Filters to target the item(s) you wish to update.

Examples

Updating your data

const { error } = await supabase
.from('countries')
.update({ name: 'Australia' })
.eq('id', 1)
const { data, error } = await supabase
.from('countries')
.select()

Update a record and return it

const { data, error } = await supabase
.from('countries')
.update({ name: 'Australia' })
.eq('id', 1)
.select()

Updating JSON data

Postgres offers some operators for working with JSON data.

const { data, error } = await supabase
.from('users')
.update({
address: {
street: 'Melrose Place',
postcode: 90210
}
})
.eq('address->postcode', 90210)
.select()

Currently, it is only possible to update the entire JSON document.