Synchronize target data from a source relation with a single statement.
Section: Insert, Update, Delete, and Merge
Merge source data
sql
sql
MERGE INTO inventory AS i
USING inventory_stage AS s
ON i.sku = s.sku
WHEN MATCHED THEN UPDATE SET qty = s.qty
WHEN NOT MATCHED THEN INSERT (sku, qty) VALUES (s.sku, s.qty);Explanation
See summary for usage details.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Insert, Update, Delete, and Merge
Insert with RETURNING
Insert rows and immediately return generated values.
Upsert with ON CONFLICT
Handle unique conflicts by updating instead of failing.