SQLSTATE 42P16Severity lowLab verified

Incident brief

Multiple primary keys not allowed

A table can have at most one PRIMARY KEY; declaring PRIMARY KEY on two columns separately raises this invalid-table-definition error. Use a composite key for several columns.

Reproduced on PostgreSQL 18.4Verified 2026-07-24 (isolated lab, PostgreSQL 18.4)Reviewed by Verified against PostgreSQL 18.4 in an isolated lab environment

In 10 seconds

What
Multiple primary keys not allowed
What triggers it
Write CREATE TABLE with PRIMARY KEY on two different columns.
The fix
Keep a single PRIMARY KEY — use one column, or a composite PRIMARY KEY (a, b).
Proof
Reproduced on PostgreSQL 18.4 → A CREATE TABLE reproduces SQLSTATE 42P16; the second PRIMARY KEY clause is rejected and the LINE points at it.

The fix

What to do right now

The immediate, application-level response to this error.

  • Keep a single PRIMARY KEY — use one column, or a composite PRIMARY KEY (a, b).
  • Model additional uniqueness with UNIQUE constraints instead of extra primary keys.
Fix — SQL
-- A table has one primary key (composite if needed).
CREATE TABLE two_pk (a int primary key, b int);

Related & next steps

Follow the thread

Everything this error touches — jump straight to the sibling error, term, runbook, or parameter.

Verification

PG 18.4
Last verified
2026-07-24 (isolated lab, PostgreSQL 18.4)
Reviewed by
Verified against PostgreSQL 18.4 in an isolated lab environment
Audit status
reviewed