How to Upsert in Snowflake with MERGE
Last updated July 24, 2026 · By the SaturnSQL team
Snowflake has no ON CONFLICT; use MERGE. It matches source rows to the target on a key, updates matches, and inserts the rest in a single atomic statement.
MERGE INTO customers t
USING staging_customers s
ON t.id = s.id
WHEN MATCHED THEN UPDATE SET
t.email = s.email,
t.updated_at = CURRENT_TIMESTAMP()
WHEN NOT MATCHED THEN INSERT (id, email, updated_at)
VALUES (s.id, s.email, CURRENT_TIMESTAMP());If the source can contain duplicate keys, deduplicate it first (e.g. QUALIFY ROW_NUMBER() ... = 1), otherwise MERGE fails with a nondeterministic-update error.
Run this in SaturnSQL
SaturnSQL is a browser-based SQL editor for teams: shared query library, schema-aware autocomplete, and scheduled exports to Google Sheets and Slack.
Try it free