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

Commit f669ba7

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 c5232dc commit f669ba7

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
@@ -940,8 +940,7 @@ DefineIndex(Oid relationId,
940940
key->partattrs[i] - 1);
941941
ereport(ERROR,
942942
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
943-
errmsg("insufficient columns in %s constraint definition",
944-
constraint_type),
943+
errmsg("unique constraint on partitioned table must include all partitioning columns"),
945944
errdetail("%s constraint on table \"%s\" lacks column \"%s\" which is part of the partition key.",
946945
constraint_type, RelationGetRelationName(rel),
947946
NameStr(att->attname))));

src/test/regress/expected/indexing.out

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -906,16 +906,16 @@ Indexes:
906906
drop table idxpart;
907907
-- Failing to use the full partition key is not allowed
908908
create table idxpart (a int unique, b int) partition by range (a, b);
909-
ERROR: insufficient columns in UNIQUE constraint definition
909+
ERROR: unique constraint on partitioned table must include all partitioning columns
910910
DETAIL: UNIQUE constraint on table "idxpart" lacks column "b" which is part of the partition key.
911911
create table idxpart (a int, b int unique) partition by range (a, b);
912-
ERROR: insufficient columns in UNIQUE constraint definition
912+
ERROR: unique constraint on partitioned table must include all partitioning columns
913913
DETAIL: UNIQUE constraint on table "idxpart" lacks column "a" which is part of the partition key.
914914
create table idxpart (a int primary key, b int) partition by range (b, a);
915-
ERROR: insufficient columns in PRIMARY KEY constraint definition
915+
ERROR: unique constraint on partitioned table must include all partitioning columns
916916
DETAIL: PRIMARY KEY constraint on table "idxpart" lacks column "b" which is part of the partition key.
917917
create table idxpart (a int, b int primary key) partition by range (b, a);
918-
ERROR: insufficient columns in PRIMARY KEY constraint definition
918+
ERROR: unique constraint on partitioned table must include all partitioning columns
919919
DETAIL: PRIMARY KEY constraint on table "idxpart" lacks column "a" which is part of the partition key.
920920
-- OK if you use them in some other order
921921
create table idxpart (a int, b int, c text, primary key (a, b, c)) partition by range (b, c, a);
@@ -935,7 +935,7 @@ DETAIL: UNIQUE constraints cannot be used when partition keys include expressio
935935
-- use ALTER TABLE to add a primary key
936936
create table idxpart (a int, b int, c text) partition by range (a, b);
937937
alter table idxpart add primary key (a); -- not an incomplete one though
938-
ERROR: insufficient columns in PRIMARY KEY constraint definition
938+
ERROR: unique constraint on partitioned table must include all partitioning columns
939939
DETAIL: PRIMARY KEY constraint on table "idxpart" lacks column "b" which is part of the partition key.
940940
alter table idxpart add primary key (a, b); -- this works
941941
\d idxpart
@@ -966,7 +966,7 @@ drop table idxpart;
966966
-- use ALTER TABLE to add a unique constraint
967967
create table idxpart (a int, b int) partition by range (a, b);
968968
alter table idxpart add unique (a); -- not an incomplete one though
969-
ERROR: insufficient columns in UNIQUE constraint definition
969+
ERROR: unique constraint on partitioned table must include all partitioning columns
970970
DETAIL: UNIQUE constraint on table "idxpart" lacks column "b" which is part of the partition key.
971971
alter table idxpart add unique (b, a); -- this works
972972
\d idxpart
@@ -1016,15 +1016,15 @@ drop table idxpart;
10161016
create table idxpart (a int, b int, primary key (a)) partition by range (a);
10171017
create table idxpart2 partition of idxpart
10181018
for values from (0) to (1000) partition by range (b); -- fail
1019-
ERROR: insufficient columns in PRIMARY KEY constraint definition
1019+
ERROR: unique constraint on partitioned table must include all partitioning columns
10201020
DETAIL: PRIMARY KEY constraint on table "idxpart2" lacks column "b" which is part of the partition key.
10211021
drop table idxpart;
10221022
-- Ditto for the ATTACH PARTITION case
10231023
create table idxpart (a int unique, b int) partition by range (a);
10241024
create table idxpart1 (a int not null, b int, unique (a, b))
10251025
partition by range (a, b);
10261026
alter table idxpart attach partition idxpart1 for values from (1) to (1000);
1027-
ERROR: insufficient columns in UNIQUE constraint definition
1027+
ERROR: unique constraint on partitioned table must include all partitioning columns
10281028
DETAIL: UNIQUE constraint on table "idxpart1" lacks column "b" which is part of the partition key.
10291029
DROP TABLE idxpart, idxpart1;
10301030
-- Multi-layer partitioning works correctly in this case:
@@ -1277,7 +1277,7 @@ insert into covidxpart values (4, 1);
12771277
ERROR: duplicate key value violates unique constraint "covidxpart4_a_b_idx"
12781278
DETAIL: Key (a)=(4) already exists.
12791279
create unique index on covidxpart (b) include (a); -- should fail
1280-
ERROR: insufficient columns in UNIQUE constraint definition
1280+
ERROR: unique constraint on partitioned table must include all partitioning columns
12811281
DETAIL: UNIQUE constraint on table "covidxpart" lacks column "a" which is part of the partition key.
12821282
-- check that detaching a partition also detaches the primary key constraint
12831283
create table parted_pk_detach_test (a int primary key) partition by list (a);

0 commit comments

Comments
 (0)