SQLSTATE 42601Severity mediumLab verified

Incident brief

ON CONFLICT DO UPDATE requires inference specification or constraint name

INSERT ... ON CONFLICT DO UPDATE was written without telling PostgreSQL which unique index or constraint should decide the conflict. DO UPDATE always needs an explicit arbiter, a column list or constraint name. (Bare ON CONFLICT DO NOTHING can sometimes omit it when only one unique index exists.)

What lands in your log

ERROR: ON CONFLICT DO UPDATE requires inference specification or constraint name

Reproduced on PostgreSQL 16.14Verified 2026-08-15 (Docker lab, PostgreSQL 16.14)Verified against PostgreSQL 16.14 in an isolated lab environment

In 10 seconds

What triggers it
Create a table with a primary key and a separate UNIQUE column (for example email).
Fix
Name the conflict target: ON CONFLICT (email) DO UPDATE SET ...
Proof
Reproduced on PostgreSQL 16.14 → Bare ON CONFLICT DO UPDATE failed with SQLSTATE 42601 and HINT 'For example, ON CONFLICT (column_name).'. The same INSERT with ON CONFLICT (email) DO UPDATE succeeded and updated the existing row.

Fix

What to do right now

Application-level steps for this error.

  • Name the conflict target: ON CONFLICT (email) DO UPDATE SET ...
  • Or name the unique constraint: ON CONFLICT ON CONSTRAINT table_email_key DO UPDATE SET ...
  • If you only want to skip duplicates, ON CONFLICT DO NOTHING is allowed without an inference target when a single unique index can be chosen, but DO UPDATE is never allowed without one.
  • Do not remove the unique constraint to silence the error; fix the ON CONFLICT clause.
Fix SQL
-- Tell PostgreSQL which unique key arbitrates the upsert
INSERT INTO upsert_lab (id, email, name) VALUES (2, 'a@ex.com', 'B')
  ON CONFLICT (email) DO UPDATE SET name = EXCLUDED.name
  RETURNING *;

-- Equivalent: name the unique constraint
INSERT INTO upsert_lab (id, email, name) VALUES (3, 'a@ex.com', 'C')
  ON CONFLICT ON CONSTRAINT upsert_lab_email_key DO UPDATE SET name = EXCLUDED.name
  RETURNING *;

Connected

Everything this error touches

Every page this SQLSTATE connects to: the concept that explains it, the runbooks that fix it, the parameters you tune to prevent it, and the sibling errors it travels with. All real cross-references. Jump straight in, or open the full interactive map.

Open in the interactive map →

Verification

PG 16.14
Last verified
2026-08-15 (Docker lab, PostgreSQL 16.14)
Verification scope
Verified against PostgreSQL 16.14 in an isolated lab environment
Audit status
reviewed
ShareLinkedInX

Went further?

Pro unlocks the second lab proof

Free page stops the bleeding. Pro adds the operational test, SQLSTATE audit, and deeper evidence, same error, more certainty.

FollowSubstackLinkedInnew errors · lab notes · hiring loops