Upsert: Update or Insert
An upsert is a database operation that either updates an existing record or inserts a new record into a table, depending on whether a matching record already exists.
Different databases have their own syntax for the upsert operation:
MySQL | INSERT ... ON DUPLICATE KEY UPDATE |
PostgreSQL | INSERT ... ON CONFLICT |
SQL Server | Uses the MERGE statement to combine insert, update, and sometimes delete operations. |
MongoDB | Uses the updateOne method with an upsert option. |