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.

What lands in your log

ERROR: unique constraint on partitioned table must include all partitioning columns

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

In 10 seconds

What triggers it
Create a table partitioned by RANGE on a column (e.g. id), with at least one partition.
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.

Fix

What to do right now

Application-level steps for 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);
INSERT INTO batch8_sales(id, region, amount)
VALUES (1, 'north', 10);

Verification

PG 16.14
Last verified
2026-07-16 (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