Commit 9fc21227 authored by Alvaro Herrera's avatar Alvaro Herrera

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: default avatarNagaraj Raj <nagaraj.sf@yahoo.com>
Discussion: https://postgr.es/m/64062533.78364.1601415362244@mail.yahoo.com
parent 489c9c34
...@@ -1002,8 +1002,7 @@ DefineIndex(Oid relationId, ...@@ -1002,8 +1002,7 @@ DefineIndex(Oid relationId,
key->partattrs[i] - 1); key->partattrs[i] - 1);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("insufficient columns in %s constraint definition", errmsg("unique constraint on partitioned table must include all partitioning columns"),
constraint_type),
errdetail("%s constraint on table \"%s\" lacks column \"%s\" which is part of the partition key.", errdetail("%s constraint on table \"%s\" lacks column \"%s\" which is part of the partition key.",
constraint_type, RelationGetRelationName(rel), constraint_type, RelationGetRelationName(rel),
NameStr(att->attname)))); NameStr(att->attname))));
......
...@@ -907,16 +907,16 @@ Indexes: ...@@ -907,16 +907,16 @@ Indexes:
drop table idxpart; drop table idxpart;
-- Failing to use the full partition key is not allowed -- Failing to use the full partition key is not allowed
create table idxpart (a int unique, b int) partition by range (a, b); create table idxpart (a int unique, b int) partition by range (a, b);
ERROR: insufficient columns in UNIQUE constraint definition 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. DETAIL: UNIQUE constraint on 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); create table idxpart (a int, b int unique) partition by range (a, b);
ERROR: insufficient columns in UNIQUE constraint definition 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. DETAIL: UNIQUE constraint on 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); create table idxpart (a int primary key, b int) partition by range (b, a);
ERROR: insufficient columns in PRIMARY KEY constraint definition 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. DETAIL: PRIMARY KEY constraint on 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); create table idxpart (a int, b int primary key) partition by range (b, a);
ERROR: insufficient columns in PRIMARY KEY constraint definition 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. DETAIL: PRIMARY KEY constraint on table "idxpart" lacks column "a" which is part of the partition key.
-- OK if you use them in some other order -- 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); 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 ...@@ -936,7 +936,7 @@ DETAIL: UNIQUE constraints cannot be used when partition keys include expressio
-- use ALTER TABLE to add a primary key -- use ALTER TABLE to add a primary key
create table idxpart (a int, b int, c text) partition by range (a, b); 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 alter table idxpart add primary key (a); -- not an incomplete one though
ERROR: insufficient columns in PRIMARY KEY constraint definition 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. DETAIL: PRIMARY KEY constraint on table "idxpart" lacks column "b" which is part of the partition key.
alter table idxpart add primary key (a, b); -- this works alter table idxpart add primary key (a, b); -- this works
\d idxpart \d idxpart
...@@ -967,7 +967,7 @@ drop table idxpart; ...@@ -967,7 +967,7 @@ drop table idxpart;
-- use ALTER TABLE to add a unique constraint -- use ALTER TABLE to add a unique constraint
create table idxpart (a int, b int) partition by range (a, b); create table idxpart (a int, b int) partition by range (a, b);
alter table idxpart add unique (a); -- not an incomplete one though alter table idxpart add unique (a); -- not an incomplete one though
ERROR: insufficient columns in UNIQUE constraint definition 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. DETAIL: UNIQUE constraint on table "idxpart" lacks column "b" which is part of the partition key.
alter table idxpart add unique (b, a); -- this works alter table idxpart add unique (b, a); -- this works
\d idxpart \d idxpart
...@@ -1017,7 +1017,7 @@ drop table idxpart; ...@@ -1017,7 +1017,7 @@ drop table idxpart;
create table idxpart (a int, b int, primary key (a)) partition by range (a); create table idxpart (a int, b int, primary key (a)) partition by range (a);
create table idxpart2 partition of idxpart create table idxpart2 partition of idxpart
for values from (0) to (1000) partition by range (b); -- fail for values from (0) to (1000) partition by range (b); -- fail
ERROR: insufficient columns in PRIMARY KEY constraint definition 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. DETAIL: PRIMARY KEY constraint on table "idxpart2" lacks column "b" which is part of the partition key.
drop table idxpart; drop table idxpart;
-- Ditto for the ATTACH PARTITION case -- Ditto for the ATTACH PARTITION case
...@@ -1025,7 +1025,7 @@ create table idxpart (a int unique, b int) partition by range (a); ...@@ -1025,7 +1025,7 @@ create table idxpart (a int unique, b int) partition by range (a);
create table idxpart1 (a int not null, b int, unique (a, b)) create table idxpart1 (a int not null, b int, unique (a, b))
partition by range (a, b); partition by range (a, b);
alter table idxpart attach partition idxpart1 for values from (1) to (1000); alter table idxpart attach partition idxpart1 for values from (1) to (1000);
ERROR: insufficient columns in UNIQUE constraint definition 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. DETAIL: UNIQUE constraint on table "idxpart1" lacks column "b" which is part of the partition key.
DROP TABLE idxpart, idxpart1; DROP TABLE idxpart, idxpart1;
-- Multi-layer partitioning works correctly in this case: -- Multi-layer partitioning works correctly in this case:
...@@ -1278,7 +1278,7 @@ insert into covidxpart values (4, 1); ...@@ -1278,7 +1278,7 @@ insert into covidxpart values (4, 1);
ERROR: duplicate key value violates unique constraint "covidxpart4_a_b_idx" ERROR: duplicate key value violates unique constraint "covidxpart4_a_b_idx"
DETAIL: Key (a)=(4) already exists. DETAIL: Key (a)=(4) already exists.
create unique index on covidxpart (b) include (a); -- should fail create unique index on covidxpart (b) include (a); -- should fail
ERROR: insufficient columns in UNIQUE constraint definition 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. DETAIL: UNIQUE constraint on table "covidxpart" lacks column "a" which is part of the partition key.
-- check that detaching a partition also detaches the primary key constraint -- 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_test (a int primary key) partition by list (a);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment