Upsert

An upsert inserts a row if its key doesn't exist, and updates it if it already exists. It makes loading idempotent: rerunning the process doesn't create duplicates. Depending on the database, it is written with INSERT … ON CONFLICT DO UPDATE (PostgreSQL) or MERGE.

Example

INSERT INTO clients (id, nom) VALUES (1, 'Ada')
ON CONFLICT (id) DO UPDATE SET nom = EXCLUDED.nom;

Related concepts

The whole glossary