Upsert data: upsert()
Performs an UPSERT into the table.
- JavaScript
const { data, error } = await supabase
.from('messages')
.upsert({ id: 3, message: 'foo', username: 'supabot' })
Parameters
valuesrequired
Partial
|array
The values to insert.
__namedParametersrequired
object
No description provided.
returningrequired
minimal
|representation
By default the new record is returned. Set this to 'minimal' if you don't need this value.
onConflictrequired
undefined
|string
By specifying the
on_conflict
query parameter, you can make UPSERT work on a column(s) that has a UNIQUE constraint.countrequired
null
|exact
|planned
|estimated
Count algorithm to use to count rows in a table.
Properties
Notes
- Primary keys should to 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.
Examples
Upsert your data
- JavaScript
const { data, error } = await supabase
.from('messages')
.upsert({ id: 3, message: 'foo', username: 'supabot' })
Upserting into tables with constraints
- JavaScript
const { data, error } = await supabase
.from('users')
.upsert({ username: 'supabot' }, { onConflict: 'username' })
Return the exact number of rows
- JavaScript
const { data, error, count } = await supabase
.from('users')
.upsert({
id: 3, message: 'foo',
username: 'supabot'
}, {
count: 'exact'
})