upserts
Upsert, a portmanteau of update and insert, refers to a database operation that inserts a new row or updates an existing one when a conflict on a unique or primary key arises. The upsert merges insert and update into a single atomic operation, ensuring a row with the given key exists with the latest data without requiring separate read and write steps.
Implementation details vary by database system. In PostgreSQL, the construct is INSERT ... ON CONFLICT (constraint) DO
These constructions enable idempotent write operations and simplify application logic, but they introduce concurrency considerations, constraint
Common use cases include synchronizing records from external sources, maintaining caches, and upserting user or product
Example (PostgreSQL): insert into users (id, name) values (1, 'Alice') on conflict (id) do update set name