Upsert Rows

The Upsert Rows stage inserts a new row, or if it already exists (based on a unique column), updates that row instead. This is useful for syncing data when you don't know if a record exists.

Overview

Input Parameters

ParameterVariableRequiredDescription
Table Name{{tableName}}YesThe name of the table to upsert into
Body Payload{{bodyPayload}}YesJSON string containing the row data
On Conflict{{onConflict}}YesUnique column(s) to check for existing rows


 

How It Works

If Row with Conflict Column Value...Action
Does NOT existINSERT new row
Already existsUPDATE existing row


 

On Conflict Options

Single Column:

email

Multiple Columns (Composite Key):

warehouse_id,product_id

Important: The column(s) specified in onConflict must have a unique constraint in your Supabase table.


 

Output

OutputVariableDescription
Upserted Rows{{upsertedRows}}Array containing the inserted or updated row
Success{{success}}Boolean indicating if the operation succeeded


 

Usage Examples

Example 1: Upsert with Single Unique Column

ParameterValue
tableNameusers
bodyPayload"{\"email\": \"[email protected]\", \"name\": \"John Doe\", \"status\": \"active\"}"
onConflictemail


 

Example 2: Upsert with Composite Key

ParameterValue
tableNameinventory
bodyPayload"{\"warehouse_id\": 1, \"product_id\": 100, \"quantity\": 50}"
onConflictwarehouse_id,product_id


 

Example 3: Sync External Data

ParameterValue
tableNameproducts
bodyPayload"{\"sku\": \"ABC-123\", \"name\": \"Widget\", \"price\": 29.99, \"stock\": 100}"
onConflictsku


 

When to Use Upsert vs Insert vs Update

ScenarioUseWhy
User registrationInsertShould error if email exists
Edit user profileUpdateUser must exist
Sync from external APIUpsertDon't know if record exists
Import CSV dataUpsertAvoid duplicates automatically
Track daily statsUpsertCreate first time, update after

Was this article helpful?