Upsert data
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
.
- Primary keys must be included in
values
to use upsert.
Parameters
- valuesREQUIREDobject
The values to upsert with. Pass an object to upsert a single row or an array to upsert multiple rows.
- optionsOptionalobject
Named parameters
countOptional"exact" | "planned" | "estimated"Count algorithm to use to count upserted 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.
ignoreDuplicatesOptionalbooleanIf `true`, duplicate rows are ignored. If `false`, duplicate rows are merged with existing rows.
onConflictOptionalstringComma-separated UNIQUE column(s) to specify how duplicate rows are determined. Two rows are duplicates if all the `onConflict` columns are equal.
const { data, error } = await supabase
.from('countries')
.upsert({ id: 1, name: 'Albania' })
.select()