Skip to content

Commit 63cbee6

Browse files
committed
doc: Reword restriction on partition keys in unique indexes
New wording from David G. Johnston, who noticed the unreadable original also. Include his suggested test case as well. Fix a typo I noticed elsewhere while doing this. Discussion: https://postgr.es/m/CAKFQuwY4Ld7ecxL_KAmaxwt0FUu5VcPPN2L4dh+3BeYbrdBa5g@mail.gmail.com
1 parent 3beb46a commit 63cbee6

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

doc/src/sgml/ref/create_table.sgml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -791,11 +791,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
791791
</para>
792792

793793
<para>
794-
When used on partitioned tables, unique constraints must include all the
795-
columns of the partition key.
796-
If any partitions are in turn partitioned, all columns of each partition
797-
key are considered at each level below the <literal>UNIQUE</literal>
798-
constraint.
794+
When establishing a unique constraint for a multi-level partition
795+
hierarchy, all the columns in the partition key of the target
796+
partitioned table, as well as those of all its descendant partitioned
797+
tables, must be included in the constraint definition.
799798
</para>
800799
</listitem>
801800
</varlistentry>

src/test/regress/expected/alter_table.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3646,7 +3646,7 @@ ALTER TABLE list_parted2 ATTACH PARTITION list_parted2 FOR VALUES IN (0);
36463646
ERROR: circular inheritance not allowed
36473647
DETAIL: "list_parted2" is already a child of "list_parted2".
36483648
-- If a partitioned table being created or an existing table being attached
3649-
-- as a paritition does not have a constraint that would allow validation scan
3649+
-- as a partition does not have a constraint that would allow validation scan
36503650
-- to be skipped, but an individual partition does, then the partition's
36513651
-- validation scan is skipped.
36523652
CREATE TABLE quuux (a int, b text) PARTITION BY LIST (a);

src/test/regress/expected/indexing.out

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,14 @@ for values from (0) to (1000) partition by range (b); -- fail
885885
ERROR: insufficient columns in PRIMARY KEY constraint definition
886886
DETAIL: PRIMARY KEY constraint on table "idxpart2" lacks column "b" which is part of the partition key.
887887
drop table idxpart;
888+
-- Ditto for the ATTACH PARTITION case
889+
create table idxpart (a int primary key, b int) partition by range (a);
890+
create table idxpart1 (a int not null, b int, primary key (a, b))
891+
partition by range (a, b);
892+
alter table idxpart attach partition idxpart1 for values from (1) to (1000);
893+
ERROR: insufficient columns in PRIMARY KEY constraint definition
894+
DETAIL: PRIMARY KEY constraint on table "idxpart1" lacks column "b" which is part of the partition key.
895+
DROP TABLE idxpart, idxpart1;
888896
-- Multi-layer partitioning works correctly in this case:
889897
create table idxpart (a int, b int, primary key (a, b)) partition by range (a);
890898
create table idxpart2 partition of idxpart for values from (0) to (1000) partition by range (b);

src/test/regress/sql/alter_table.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2348,7 +2348,7 @@ ALTER TABLE part_5 ATTACH PARTITION list_parted2 FOR VALUES IN ('b');
23482348
ALTER TABLE list_parted2 ATTACH PARTITION list_parted2 FOR VALUES IN (0);
23492349

23502350
-- If a partitioned table being created or an existing table being attached
2351-
-- as a paritition does not have a constraint that would allow validation scan
2351+
-- as a partition does not have a constraint that would allow validation scan
23522352
-- to be skipped, but an individual partition does, then the partition's
23532353
-- validation scan is skipped.
23542354
CREATE TABLE quuux (a int, b text) PARTITION BY LIST (a);

src/test/regress/sql/indexing.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,13 @@ create table idxpart2 partition of idxpart
450450
for values from (0) to (1000) partition by range (b); -- fail
451451
drop table idxpart;
452452

453+
-- Ditto for the ATTACH PARTITION case
454+
create table idxpart (a int primary key, b int) partition by range (a);
455+
create table idxpart1 (a int not null, b int, primary key (a, b))
456+
partition by range (a, b);
457+
alter table idxpart attach partition idxpart1 for values from (1) to (1000);
458+
DROP TABLE idxpart, idxpart1;
459+
453460
-- Multi-layer partitioning works correctly in this case:
454461
create table idxpart (a int, b int, primary key (a, b)) partition by range (a);
455462
create table idxpart2 partition of idxpart for values from (0) to (1000) partition by range (b);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy