Upsert data: upsert()

Performs an UPSERT into the table.

const { data, error } = await supabase
.upsert({ id: 3, message: 'foo', username: 'supabot' })


  • valuesrequiredPartial | array

    The values to insert.

  • __namedParametersrequiredobject

    No description provided.

    • returningrequiredminimal | representation

      By default the new record is returned. Set this to 'minimal' if you don't need this value.

    • onConflictrequiredundefined | string

      By specifying the on_conflict query parameter, you can make UPSERT work on a column(s) that has a UNIQUE constraint.

    • ignoreDuplicatesrequiredboolean

      Specifies if duplicate rows should be ignored and not inserted.

    • countrequirednull | exact | planned | estimated

      Count algorithm to use to count rows in a table.


  • 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.


Upsert your data

const { data, error } = await supabase
.upsert({ id: 3, message: 'foo', username: 'supabot' })

Upserting into tables with constraints

Running the following will cause supabase to upsert data into the users table. If the username 'supabot' already exists, the onConflict argument tells supabase to overwrite that row based on the column passed into onConflict.

const { data, error } = await supabase
.upsert({ username: 'supabot' }, { onConflict: 'username' })

Return the exact number of rows

const { data, error, count } = await supabase
id: 3, message: 'foo',
username: 'supabot'
}, {
count: 'exact'