Insert-or-update without a race
The classic anti-pattern: "check if a row exists; if so UPDATE, else INSERT." Two of those running concurrently both see "doesn't exist," both INSERT, and one fails on the unique constraint. PostgreSQL's ON CONFLICT clause makes the whole operation atomic.
Three shapes you'll use
ON CONFLICT (col) DO NOTHING— silent dedup; useful for "insert if not present."ON CONFLICT (col) DO UPDATE SET ...— true upsert; insert or update.ON CONFLICT ON CONSTRAINT name DO ...— when you want to target a named constraint instead of guessing the column.
EXCLUDED — the row that tried to insert
Inside DO UPDATE, the keyword EXCLUDED refers to the row from the INSERT. Without prefix, column names refer to the existing row. This lets you choose: keep the old value, take the new one, or compute from both.