Insert rows that don't exist and update those that do in one statement.
Insert a row if it does not exist, or update it if it does. PostgreSQL uses INSERT ... ON CONFLICT DO UPDATE; MySQL uses INSERT ... ON DUPLICATE KEY UPDATE; SQL Server uses MERGE. Essential for idempotent data ingestion pipelines.
| Database System | Support Status | Since Version | Notes |
|---|---|---|---|
| MySQL | ✓ Supported | 5.1 | ON DUPLICATE KEY UPDATE |
| PostgreSQL | ✓ Supported | 9.5 | ON CONFLICT DO UPDATE |
| SQL Server | ✓ Supported | 2008 | Via MERGE |
| Oracle | ✓ Supported | 9i | Via MERGE |
| SQLite | ✓ Supported | 3.24.0 | INSERT…ON CONFLICT |
Atomic insert-or-update in one shot.
ON DUPLICATE KEY UPDATE
ON CONFLICT DO UPDATE
Via MERGE
Via MERGE
INSERT…ON CONFLICT