Skip to content

Commit 5b76e8f

Browse files
committed
Reword partitioning error message
The error message about columns in the primary key not including all of the partition key was unclear; reword it. Backpatch all the way to pg11, where it appeared. Reported-by: Nagaraj Raj <nagaraj.sf@yahoo.com> Discussion: https://postgr.es/m/64062533.78364.1601415362244@mail.yahoo.com
1 parent b0fe0b0 commit 5b76e8f

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/backend/commands/indexcmds.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,8 +810,7 @@ DefineIndex(Oid relationId,
810810
key->partattrs[i] - 1);
811811
ereport(ERROR,
812812
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
813-
errmsg("insufficient columns in %s constraint definition",
814-
constraint_type),
813+
errmsg("unique constraint on partitioned table must include all partitioning columns"),
815814
errdetail("%s constraint on table \"%s\" lacks column \"%s\" which is part of the partition key.",
816815
constraint_type, RelationGetRelationName(rel),
817816
NameStr(att->attname))));

src/test/regress/expected/indexing.out

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -855,16 +855,16 @@ Indexes:
855855
drop table idxpart;
856856
-- Failing to use the full partition key is not allowed
857857
create table idxpart (a int unique, b int) partition by range (a, b);
858-
ERROR: insufficient columns in UNIQUE constraint definition
858+
ERROR: unique constraint on partitioned table must include all partitioning columns
859859
DETAIL: UNIQUE constraint on table "idxpart" lacks column "b" which is part of the partition key.
860860
create table idxpart (a int, b int unique) partition by range (a, b);
861-
ERROR: insufficient columns in UNIQUE constraint definition
861+
ERROR: unique constraint on partitioned table must include all partitioning columns
862862
DETAIL: UNIQUE constraint on table "idxpart" lacks column "a" which is part of the partition key.
863863
create table idxpart (a int primary key, b int) partition by range (b, a);
864-
ERROR: insufficient columns in PRIMARY KEY constraint definition
864+
ERROR: unique constraint on partitioned table must include all partitioning columns
865865
DETAIL: PRIMARY KEY constraint on table "idxpart" lacks column "b" which is part of the partition key.
866866
create table idxpart (a int, b int primary key) partition by range (b, a);
867-
ERROR: insufficient columns in PRIMARY KEY constraint definition
867+
ERROR: unique constraint on partitioned table must include all partitioning columns
868868
DETAIL: PRIMARY KEY constraint on table "idxpart" lacks column "a" which is part of the partition key.
869869
-- OK if you use them in some other order
870870
create table idxpart (a int, b int, c text, primary key (a, b, c)) partition by range (b, c, a);
@@ -884,7 +884,7 @@ DETAIL: UNIQUE constraints cannot be used when partition keys include expressio
884884
-- use ALTER TABLE to add a primary key
885885
create table idxpart (a int, b int, c text) partition by range (a, b);
886886
alter table idxpart add primary key (a); -- not an incomplete one though
887-
ERROR: insufficient columns in PRIMARY KEY constraint definition
887+
ERROR: unique constraint on partitioned table must include all partitioning columns
888888
DETAIL: PRIMARY KEY constraint on table "idxpart" lacks column "b" which is part of the partition key.
889889
alter table idxpart add primary key (a, b); -- this works
890890
\d idxpart
@@ -915,7 +915,7 @@ drop table idxpart;
915915
-- use ALTER TABLE to add a unique constraint
916916
create table idxpart (a int, b int) partition by range (a, b);
917917
alter table idxpart add unique (a); -- not an incomplete one though
918-
ERROR: insufficient columns in UNIQUE constraint definition
918+
ERROR: unique constraint on partitioned table must include all partitioning columns
919919
DETAIL: UNIQUE constraint on table "idxpart" lacks column "b" which is part of the partition key.
920920
alter table idxpart add unique (b, a); -- this works
921921
\d idxpart
@@ -965,15 +965,15 @@ drop table idxpart;
965965
create table idxpart (a int, b int, primary key (a)) partition by range (a);
966966
create table idxpart2 partition of idxpart
967967
for values from (0) to (1000) partition by range (b); -- fail
968-
ERROR: insufficient columns in PRIMARY KEY constraint definition
968+
ERROR: unique constraint on partitioned table must include all partitioning columns
969969
DETAIL: PRIMARY KEY constraint on table "idxpart2" lacks column "b" which is part of the partition key.
970970
drop table idxpart;
971971
-- Ditto for the ATTACH PARTITION case
972972
create table idxpart (a int unique, b int) partition by range (a);
973973
create table idxpart1 (a int not null, b int, unique (a, b))
974974
partition by range (a, b);
975975
alter table idxpart attach partition idxpart1 for values from (1) to (1000);
976-
ERROR: insufficient columns in UNIQUE constraint definition
976+
ERROR: unique constraint on partitioned table must include all partitioning columns
977977
DETAIL: UNIQUE constraint on table "idxpart1" lacks column "b" which is part of the partition key.
978978
DROP TABLE idxpart, idxpart1;
979979
-- Multi-layer partitioning works correctly in this case:
@@ -1426,7 +1426,7 @@ insert into covidxpart values (4, 1);
14261426
ERROR: duplicate key value violates unique constraint "covidxpart4_a_b_idx"
14271427
DETAIL: Key (a)=(4) already exists.
14281428
create unique index on covidxpart (b) include (a); -- should fail
1429-
ERROR: insufficient columns in UNIQUE constraint definition
1429+
ERROR: unique constraint on partitioned table must include all partitioning columns
14301430
DETAIL: UNIQUE constraint on table "covidxpart" lacks column "a" which is part of the partition key.
14311431
-- check that detaching a partition also detaches the primary key constraint
14321432
create table parted_pk_detach_test (a int primary key) partition by list (a);

0 commit comments

Comments
 (0)