Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9fc2122

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 489c9c3 commit 9fc2122

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/backend/commands/indexcmds.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -1002,8 +1002,7 @@ DefineIndex(Oid relationId,
10021002
key->partattrs[i] - 1);
10031003
ereport(ERROR,
10041004
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1005-
errmsg("insufficient columns in %s constraint definition",
1006-
constraint_type),
1005+
errmsg("unique constraint on partitioned table must include all partitioning columns"),
10071006
errdetail("%s constraint on table \"%s\" lacks column \"%s\" which is part of the partition key.",
10081007
constraint_type, RelationGetRelationName(rel),
10091008
NameStr(att->attname))));

src/test/regress/expected/indexing.out

+9-9
Original file line numberDiff line numberDiff line change
@@ -907,16 +907,16 @@ Indexes:
907907
drop table idxpart;
908908
-- Failing to use the full partition key is not allowed
909909
create table idxpart (a int unique, b int) partition by range (a, b);
910-
ERROR: insufficient columns in UNIQUE constraint definition
910+
ERROR: unique constraint on partitioned table must include all partitioning columns
911911
DETAIL: UNIQUE constraint on table "idxpart" lacks column "b" which is part of the partition key.
912912
create table idxpart (a int, b int unique) partition by range (a, b);
913-
ERROR: insufficient columns in UNIQUE constraint definition
913+
ERROR: unique constraint on partitioned table must include all partitioning columns
914914
DETAIL: UNIQUE constraint on table "idxpart" lacks column "a" which is part of the partition key.
915915
create table idxpart (a int primary key, b int) partition by range (b, a);
916-
ERROR: insufficient columns in PRIMARY KEY constraint definition
916+
ERROR: unique constraint on partitioned table must include all partitioning columns
917917
DETAIL: PRIMARY KEY constraint on table "idxpart" lacks column "b" which is part of the partition key.
918918
create table idxpart (a int, b int primary key) partition by range (b, a);
919-
ERROR: insufficient columns in PRIMARY KEY constraint definition
919+
ERROR: unique constraint on partitioned table must include all partitioning columns
920920
DETAIL: PRIMARY KEY constraint on table "idxpart" lacks column "a" which is part of the partition key.
921921
-- OK if you use them in some other order
922922
create table idxpart (a int, b int, c text, primary key (a, b, c)) partition by range (b, c, a);
@@ -936,7 +936,7 @@ DETAIL: UNIQUE constraints cannot be used when partition keys include expressio
936936
-- use ALTER TABLE to add a primary key
937937
create table idxpart (a int, b int, c text) partition by range (a, b);
938938
alter table idxpart add primary key (a); -- not an incomplete one though
939-
ERROR: insufficient columns in PRIMARY KEY constraint definition
939+
ERROR: unique constraint on partitioned table must include all partitioning columns
940940
DETAIL: PRIMARY KEY constraint on table "idxpart" lacks column "b" which is part of the partition key.
941941
alter table idxpart add primary key (a, b); -- this works
942942
\d idxpart
@@ -967,7 +967,7 @@ drop table idxpart;
967967
-- use ALTER TABLE to add a unique constraint
968968
create table idxpart (a int, b int) partition by range (a, b);
969969
alter table idxpart add unique (a); -- not an incomplete one though
970-
ERROR: insufficient columns in UNIQUE constraint definition
970+
ERROR: unique constraint on partitioned table must include all partitioning columns
971971
DETAIL: UNIQUE constraint on table "idxpart" lacks column "b" which is part of the partition key.
972972
alter table idxpart add unique (b, a); -- this works
973973
\d idxpart
@@ -1017,15 +1017,15 @@ drop table idxpart;
10171017
create table idxpart (a int, b int, primary key (a)) partition by range (a);
10181018
create table idxpart2 partition of idxpart
10191019
for values from (0) to (1000) partition by range (b); -- fail
1020-
ERROR: insufficient columns in PRIMARY KEY constraint definition
1020+
ERROR: unique constraint on partitioned table must include all partitioning columns
10211021
DETAIL: PRIMARY KEY constraint on table "idxpart2" lacks column "b" which is part of the partition key.
10221022
drop table idxpart;
10231023
-- Ditto for the ATTACH PARTITION case
10241024
create table idxpart (a int unique, b int) partition by range (a);
10251025
create table idxpart1 (a int not null, b int, unique (a, b))
10261026
partition by range (a, b);
10271027
alter table idxpart attach partition idxpart1 for values from (1) to (1000);
1028-
ERROR: insufficient columns in UNIQUE constraint definition
1028+
ERROR: unique constraint on partitioned table must include all partitioning columns
10291029
DETAIL: UNIQUE constraint on table "idxpart1" lacks column "b" which is part of the partition key.
10301030
DROP TABLE idxpart, idxpart1;
10311031
-- Multi-layer partitioning works correctly in this case:
@@ -1278,7 +1278,7 @@ insert into covidxpart values (4, 1);
12781278
ERROR: duplicate key value violates unique constraint "covidxpart4_a_b_idx"
12791279
DETAIL: Key (a)=(4) already exists.
12801280
create unique index on covidxpart (b) include (a); -- should fail
1281-
ERROR: insufficient columns in UNIQUE constraint definition
1281+
ERROR: unique constraint on partitioned table must include all partitioning columns
12821282
DETAIL: UNIQUE constraint on table "covidxpart" lacks column "a" which is part of the partition key.
12831283
-- check that detaching a partition also detaches the primary key constraint
12841284
create table parted_pk_detach_test (a int primary key) partition by list (a);

0 commit comments

Comments
 (0)