On Mon, Nov 17, 2025 at 8:52 PM Daniel Gustafsson <[email protected]> wrote:
>
> Some of the internals does seem bleed through. Do you want to work on a patch
> for a suggestion on an improvement? Maybe it could be possible to improve the
> wording by incorporating constraint_type in some way?
>
I have changed this ereport:
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("unique constraint on partitioned table must include
all partitioning columns"),
errdetail("%s constraint on table \"%s\" lacks column \"%s\"
which is part of the partition key.",
constraint_type, RelationGetRelationName(rel),
NameStr(att->attname))));
to
+ errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("%s constraint on partitioned table
must include all partitioning columns", constraint_type),
+ errdetail("%s constraint on partitioned table
\"%s\" lacks column \"%s\" which is part of the partition key.",
+ constraint_type,
RelationGetRelationName(rel),
+ NameStr(att->attname)));
From 96257504c1205e06a4a88f59bf1ab2692df25db5 Mon Sep 17 00:00:00 2001
From: jian he <[email protected]>
Date: Tue, 18 Nov 2025 15:13:47 +0800
Subject: [PATCH v1 1/1] Minor enhancement to the error message in DefineIndex
discussion: https://postgr.es/m/CACJufxH6VhAf65Vghg4T2q315gY=rt4bufmyunkfrj0n2s9...@mail.gmail.com
---
src/backend/commands/indexcmds.c | 10 ++---
src/test/regress/expected/indexing.out | 52 +++++++++++++-------------
2 files changed, 31 insertions(+), 31 deletions(-)
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index 221c7d1d607..8ad00d0e63b 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -1088,11 +1088,11 @@ DefineIndex(Oid tableId,
att = TupleDescAttr(RelationGetDescr(rel),
key->partattrs[i] - 1);
ereport(ERROR,
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("unique constraint on partitioned table must include all partitioning columns"),
- errdetail("%s constraint on table \"%s\" lacks column \"%s\" which is part of the partition key.",
- constraint_type, RelationGetRelationName(rel),
- NameStr(att->attname))));
+ errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("%s constraint on partitioned table must include all partitioning columns", constraint_type),
+ errdetail("%s constraint on partitioned table \"%s\" lacks column \"%s\" which is part of the partition key.",
+ constraint_type, RelationGetRelationName(rel),
+ NameStr(att->attname)));
}
}
}
diff --git a/src/test/regress/expected/indexing.out b/src/test/regress/expected/indexing.out
index 4d29fb85293..acd0af84a45 100644
--- a/src/test/regress/expected/indexing.out
+++ b/src/test/regress/expected/indexing.out
@@ -972,17 +972,17 @@ Indexes:
drop table idxpart;
-- Failing to use the full partition key is not allowed
create table idxpart (a int unique, b int) partition by range (a, b);
-ERROR: unique constraint on partitioned table must include all partitioning columns
-DETAIL: UNIQUE constraint on table "idxpart" lacks column "b" which is part of the partition key.
+ERROR: UNIQUE constraint on partitioned table must include all partitioning columns
+DETAIL: UNIQUE constraint on partitioned table "idxpart" lacks column "b" which is part of the partition key.
create table idxpart (a int, b int unique) partition by range (a, b);
-ERROR: unique constraint on partitioned table must include all partitioning columns
-DETAIL: UNIQUE constraint on table "idxpart" lacks column "a" which is part of the partition key.
+ERROR: UNIQUE constraint on partitioned table must include all partitioning columns
+DETAIL: UNIQUE constraint on partitioned table "idxpart" lacks column "a" which is part of the partition key.
create table idxpart (a int primary key, b int) partition by range (b, a);
-ERROR: unique constraint on partitioned table must include all partitioning columns
-DETAIL: PRIMARY KEY constraint on table "idxpart" lacks column "b" which is part of the partition key.
+ERROR: PRIMARY KEY constraint on partitioned table must include all partitioning columns
+DETAIL: PRIMARY KEY constraint on partitioned table "idxpart" lacks column "b" which is part of the partition key.
create table idxpart (a int, b int primary key) partition by range (b, a);
-ERROR: unique constraint on partitioned table must include all partitioning columns
-DETAIL: PRIMARY KEY constraint on table "idxpart" lacks column "a" which is part of the partition key.
+ERROR: PRIMARY KEY constraint on partitioned table must include all partitioning columns
+DETAIL: PRIMARY KEY constraint on partitioned table "idxpart" lacks column "a" which is part of the partition key.
-- OK if you use them in some other order
create table idxpart (a int, b int, c text, primary key (a, b, c)) partition by range (b, c, a);
drop table idxpart;
@@ -997,8 +997,8 @@ create table idxpart (a int4range, b int4range, exclude USING GIST (a with =, b
drop table idxpart;
-- Not OK more than one equal column: partition keys are a proper superset of constraint
create table idxpart (a int4range, b int4range, exclude USING GIST (a with = )) partition by range (a, b);
-ERROR: unique constraint on partitioned table must include all partitioning columns
-DETAIL: EXCLUDE constraint on table "idxpart" lacks column "b" which is part of the partition key.
+ERROR: EXCLUDE constraint on partitioned table must include all partitioning columns
+DETAIL: EXCLUDE constraint on partitioned table "idxpart" lacks column "b" which is part of the partition key.
-- Not OK with just -|-
create table idxpart (a int4range, exclude USING GIST (a with -|- )) partition by range (a);
ERROR: cannot match partition key to index on column "a" using non-equal operator "-|-"
@@ -1007,8 +1007,8 @@ create table idxpart (a int4range, b int4range, exclude USING GIST (a with =, b
drop table idxpart;
-- Not OK with equals and &&, and equals is not the partition key
create table idxpart (a int4range, b int4range, c int4range, exclude USING GIST (b with =, c with &&)) partition by range (a);
-ERROR: unique constraint on partitioned table must include all partitioning columns
-DETAIL: EXCLUDE constraint on table "idxpart" lacks column "a" which is part of the partition key.
+ERROR: EXCLUDE constraint on partitioned table must include all partitioning columns
+DETAIL: EXCLUDE constraint on partitioned table "idxpart" lacks column "a" which is part of the partition key.
-- OK more than one equal column and a && column
create table idxpart (a int4range, b int4range, c int4range, exclude USING GIST (a with =, b with =, c with &&)) partition by range (a, b);
drop table idxpart;
@@ -1022,8 +1022,8 @@ DETAIL: UNIQUE constraints cannot be used when partition keys include expressio
-- use ALTER TABLE to add a primary key
create table idxpart (a int, b int, c text) partition by range (a, b);
alter table idxpart add primary key (a); -- not an incomplete one though
-ERROR: unique constraint on partitioned table must include all partitioning columns
-DETAIL: PRIMARY KEY constraint on table "idxpart" lacks column "b" which is part of the partition key.
+ERROR: PRIMARY KEY constraint on partitioned table must include all partitioning columns
+DETAIL: PRIMARY KEY constraint on partitioned table "idxpart" lacks column "b" which is part of the partition key.
alter table idxpart add primary key (a, b); -- this works
\d idxpart
Partitioned table "public.idxpart"
@@ -1053,8 +1053,8 @@ drop table idxpart;
-- use ALTER TABLE to add a unique constraint
create table idxpart (a int, b int) partition by range (a, b);
alter table idxpart add unique (a); -- not an incomplete one though
-ERROR: unique constraint on partitioned table must include all partitioning columns
-DETAIL: UNIQUE constraint on table "idxpart" lacks column "b" which is part of the partition key.
+ERROR: UNIQUE constraint on partitioned table must include all partitioning columns
+DETAIL: UNIQUE constraint on partitioned table "idxpart" lacks column "b" which is part of the partition key.
alter table idxpart add unique (b, a); -- this works
\d idxpart
Partitioned table "public.idxpart"
@@ -1083,8 +1083,8 @@ drop table idxpart;
-- Not OK more than one equal column: partition keys are a proper superset of constraint
create table idxpart (a int4range, b int4range) partition by range (a, b);
alter table idxpart add exclude USING GIST (a with =);
-ERROR: unique constraint on partitioned table must include all partitioning columns
-DETAIL: EXCLUDE constraint on table "idxpart" lacks column "b" which is part of the partition key.
+ERROR: EXCLUDE constraint on partitioned table must include all partitioning columns
+DETAIL: EXCLUDE constraint on partitioned table "idxpart" lacks column "b" which is part of the partition key.
drop table idxpart;
-- Not OK with just -|-
create table idxpart (a int4range, b int4range) partition by range (a, b);
@@ -1098,8 +1098,8 @@ drop table idxpart;
-- Not OK with equals and &&, and equals is not the partition key
create table idxpart (a int4range, b int4range, c int4range) partition by range (a);
alter table idxpart add exclude USING GIST (b with =, c with &&);
-ERROR: unique constraint on partitioned table must include all partitioning columns
-DETAIL: EXCLUDE constraint on table "idxpart" lacks column "a" which is part of the partition key.
+ERROR: EXCLUDE constraint on partitioned table must include all partitioning columns
+DETAIL: EXCLUDE constraint on partitioned table "idxpart" lacks column "a" which is part of the partition key.
drop table idxpart;
-- OK more than one equal column and a && column
create table idxpart (a int4range, b int4range, c int4range) partition by range (a, b);
@@ -1145,16 +1145,16 @@ drop table idxpart;
create table idxpart (a int, b int, primary key (a)) partition by range (a);
create table idxpart2 partition of idxpart
for values from (0) to (1000) partition by range (b); -- fail
-ERROR: unique constraint on partitioned table must include all partitioning columns
-DETAIL: PRIMARY KEY constraint on table "idxpart2" lacks column "b" which is part of the partition key.
+ERROR: PRIMARY KEY constraint on partitioned table must include all partitioning columns
+DETAIL: PRIMARY KEY constraint on partitioned table "idxpart2" lacks column "b" which is part of the partition key.
drop table idxpart;
-- Ditto for the ATTACH PARTITION case
create table idxpart (a int unique, b int) partition by range (a);
create table idxpart1 (a int not null, b int, unique (a, b))
partition by range (a, b);
alter table idxpart attach partition idxpart1 for values from (1) to (1000);
-ERROR: unique constraint on partitioned table must include all partitioning columns
-DETAIL: UNIQUE constraint on table "idxpart1" lacks column "b" which is part of the partition key.
+ERROR: UNIQUE constraint on partitioned table must include all partitioning columns
+DETAIL: UNIQUE constraint on partitioned table "idxpart1" lacks column "b" which is part of the partition key.
DROP TABLE idxpart, idxpart1;
-- Multi-layer partitioning works correctly in this case:
create table idxpart (a int, b int, primary key (a, b)) partition by range (a);
@@ -1448,8 +1448,8 @@ insert into covidxpart values (4, 1);
ERROR: duplicate key value violates unique constraint "covidxpart4_a_b_idx"
DETAIL: Key (a)=(4) already exists.
create unique index on covidxpart (b) include (a); -- should fail
-ERROR: unique constraint on partitioned table must include all partitioning columns
-DETAIL: UNIQUE constraint on table "covidxpart" lacks column "a" which is part of the partition key.
+ERROR: UNIQUE constraint on partitioned table must include all partitioning columns
+DETAIL: UNIQUE constraint on partitioned table "covidxpart" lacks column "a" which is part of the partition key.
-- check that detaching a partition also detaches the primary key constraint
create table parted_pk_detach_test (a int primary key) partition by list (a);
create table parted_pk_detach_test1 partition of parted_pk_detach_test for values in (1);
--
2.34.1