Skip to main content

UPSERT: SQL-UPDATE a row, or if not found INSERT a new row.

The SQL:2003 standard defines MERGE. Some implementations use the key word UPSERT.
UPSERT could be considered a subset of MERGE.

Inserting or updating a row has to deal with a possible race condition between concurrent operations.

Oracle, DB2, Teradata and MS SQL support the standard syntax for MERGE.
MongoDB, MySQL, SQLite, Firebird support similar features.
Find an UPSERT example for PostgreSQL in the manual or a detailed assessment in this blog article by @Depesz.