SQLSTATE 0A000Severity mediumLab verified

Incident brief

Unique constraint on partitioned table

A UNIQUE constraint was added to a partitioned table without including all of the partition key columns. PostgreSQL rejected it because it cannot enforce uniqueness across partitions.

Reproduced on PostgreSQL 16.14Verified 2026-07-16 (Docker lab, PostgreSQL 16.14)Reviewed by Verified against PostgreSQL 16.14 in an isolated lab environment

In 10 seconds

What
Unique constraint on partitioned table
What triggers it
Create a table partitioned by RANGE on a column (e.g. id), with at least one partition.
The fix
Include every partition key column in the UNIQUE (or PRIMARY KEY) constraint's column list.
Proof
Reproduced on PostgreSQL 16.14 → Adding a UNIQUE constraint that omitted the partition key column was rejected with SQLSTATE 0A000. The same constraint succeeded once the partition key column was included.

The fix

What to do right now

The immediate, application-level response to this error.

  • Include every partition key column in the UNIQUE (or PRIMARY KEY) constraint's column list.
  • If true cross-partition uniqueness on a non-key column is required, enforce it outside PostgreSQL or reconsider the partitioning key.
Fix — SQL
ALTER TABLE batch8_sales ADD CONSTRAINT batch8_sales_id_region_unique UNIQUE (id, region);

Related & next steps

Follow the thread

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

Verification

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