SQL Merge and Upsert Generator
Builds an upsert statement from a table definition and the key columns you nominate.
Loading the tool…
How to use this tool
- Paste the CREATE TABLE statement for the target table.
- Name the staging table and the key columns to match on, or leave them blank to use the primary key.
- Select Generate upsert, read the statement, and test it against a copy first.
What sql merge generator does
An upsert inserts rows that are new and updates rows that already exist, matched on a key. Paste the target table’s DDL, name the key columns and the staging table, and this writes the statement: ON CONFLICT DO UPDATE for PostgreSQL, and a MERGE for the platforms that use it.
Two things decide whether an upsert behaves. The key columns must be genuinely unique in the source — two staging rows with the same key will make some platforms fail the whole statement — and there must be a unique constraint on those columns in the target. Read the generated statement, check the column list, and run it against a copy before it touches anything that matters.