Upsert data
Performs an UPSERT into the table.
- Primary keys should be included in the data payload in order for an update to work correctly.
- Primary keys must be natural, not surrogate. There are however, workarounds for surrogate primary keys.
- If you need to insert new data and update existing data at the same time, use Postgres triggers.
Parameters
values
REQUIRED
objectThe values to insert.
__namedParameters
Optional
objectreturning
Optional
objectBy default the new record is returned. Set this to 'minimal' if you don't need this value.
onConflict
REQUIRED
undefined | stringBy specifying the `on_conflict` query parameter, you can make UPSERT work on a column(s) that has a UNIQUE constraint.
ignoreDuplicates
Optional
booleanSpecifies if duplicate rows should be ignored and not inserted.
count
Optional
objectCount algorithm to use to count rows in a table.
const { data, error } = await supabase
.from('messages')
.upsert({ id: 3, message: 'foo', username: 'supabot' })