Perform an UPSERT on the table or view. Depending on the column(s) passed to onConflict
, .upsert()
allows you to perform the equivalent of .insert()
if a row with the corresponding onConflict
columns doesn't exist, or if it does exist, perform an alternative action depending on ignoreDuplicates
.
values
to use upsert.The values to upsert with. Pass a Map to upsert a single row or an List to upsert multiple rows.
Comma-separated UNIQUE column(s) to specify how duplicate rows are determined. Two rows are duplicates if all the `onConflict` columns are equal.
If `true`, duplicate rows are ignored. If `false`, duplicate rows are merged with existing rows.
Make missing fields default to `null`. Otherwise, use the default value for the column. This only applies when inserting new rows, not when merging with existing rows where ignoreDuplicates is set to false. This also only applies when doing bulk upserts.
final data = await supabase
.from('countries')
.upsert(\{ 'id': 1, 'name': 'Albania' \})
.select();
final data = await supabase
.from('countries')
.upsert([
\{ 'id': 1, 'name': 'Albania' \},
\{ 'id': 2, 'name': 'Algeria' \},
])
.select();
final data = await supabase
.from('users')
.upsert(\{ 'id': 42, 'handle': 'saoirse', 'display_name': 'Saoirse' \}, \{ onConflict: 'handle' \})
.select();