SQL

UPSERT

English

Overview

An operation that updates a row if it already exists, or inserts it if it doesn't, all in a single statement.

Details

A portmanteau of UPDATE and INSERT. It removes the need to write "check first, then branch" logic in the application, simplifying the code and also preventing a race condition where something else could intervene between the check and the write. It's implemented, for example, via PostgreSQL's "INSERT ... ON CONFLICT."

More Database terms