SQL UPSERT Across Dialects: ON CONFLICT, ON DUPLICATE KEY, and MERGE
By Sharon Ben-Moshe · August 8, 2026 · 3 min read
Sharon Ben-Moshe is the founder of sqlfmt, a browser-based SQL formatter and validator with misspelled-keyword suggestions across PostgreSQL, MySQL, SQLite, SQL Server, and BigQuery.
Every major SQL dialect can insert-or-update in one statement, but the syntax is different everywhere — ON CONFLICT, ON DUPLICATE KEY UPDATE, INSERT OR REPLACE, and MERGE all solve the same problem in incompatible ways.
Quick answer
An upsert inserts a new row or updates an existing one in a single statement, avoiding a separate exists-check. PostgreSQL and SQLite use INSERT ... ON CONFLICT, MySQL uses INSERT ... ON DUPLICATE KEY UPDATE, and SQL Server and BigQuery use the ANSI MERGE statement — the same operation, five different keywords.