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.
1const { error } = await supabase
2 .from('countries')
3 .update({ name: 'Australia' })
4 .eq('id', 1)
Parameters#
valuesrequired
Row
The values to update with
optionsrequired
object
Named parameters
countoptional
|exact
|planned
estimated
Count algorithm to use to count updated rows.
"exact"
: Exact but slow count algorithm. Performs aCOUNT(*)
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
Notes#
update()
should always be combined with Filters to target the item(s) you wish to update.
Examples#
Updating your data#
1create table
2 countries (id int8 primary key, name text);
3
4insert into
5 countries (id, name)
6values
7 (1, 'Taiwan');
1const { data, error } = await supabase 2 .from('countries') 3 .select()
Update a record and return it#
1create table
2 countries (id int8 primary key, name text);
3
4insert into
5 countries (id, name)
6values
7 (1, 'Taiwan');
Updating JSON data#
Postgres offers some operators for working with JSON data.
1create table
2 users (
3 id int8 primary key,
4 name text,
5 address jsonb
6 );
7
8insert into
9 users (id, name, address)
10values
11 (1, 'Michael', '{ "postcode": 90210 }');
Currently, it is only possible to update the entire JSON document.