An eligible uniqueness rule selects the conflict. With existing total 5 and proposed total 3, an additive update yields 8 while replacement yields 3. The merge expression determines the policy.

INSERT ... ON CONFLICT turns a race into one statement

INSERT … ON CONFLICT lets PostgreSQL resolve an insert collision inside the statement that performs the write. It replaces a fragile “check whether the key exists, then insert” sequence with an explicit conflict policy backed by an eligible index or constraint. It does not turn every insertion error into a successful update or define the application’s merge policy for you. ...

March 25, 2027 · 5 min · XB Field Notes