@@ -703,16 +703,42 @@ CREATE TABLE part_b PARTITION OF parted (
703
703
) FOR VALUES IN ('b');
704
704
ERROR: column "b" specified more than once
705
705
CREATE TABLE part_b PARTITION OF parted (
706
- b NOT NULL DEFAULT 1 CHECK (b >= 0),
707
- CONSTRAINT check_a CHECK (length(a) > 0)
706
+ b NOT NULL DEFAULT 1,
707
+ CONSTRAINT check_a CHECK (length(a) > 0),
708
+ CONSTRAINT check_b CHECK (b >= 0)
708
709
) FOR VALUES IN ('b');
709
710
NOTICE: merging constraint "check_a" with inherited definition
710
- -- conislocal should be false for any merged constraints
711
- SELECT conislocal, coninhcount FROM pg_constraint WHERE conrelid = 'part_b'::regclass AND conname = 'check_a' ;
711
+ -- conislocal should be false for any merged constraints, true otherwise
712
+ SELECT conislocal, coninhcount FROM pg_constraint WHERE conrelid = 'part_b'::regclass ORDER BY conislocal, coninhcount ;
712
713
conislocal | coninhcount
713
714
------------+-------------
714
715
f | 1
715
- (1 row)
716
+ t | 0
717
+ (2 rows)
718
+
719
+ -- Once check_b is added to the parent, it should be made non-local for part_b
720
+ ALTER TABLE parted ADD CONSTRAINT check_b CHECK (b >= 0);
721
+ NOTICE: merging constraint "check_b" with inherited definition
722
+ SELECT conislocal, coninhcount FROM pg_constraint WHERE conrelid = 'part_b'::regclass;
723
+ conislocal | coninhcount
724
+ ------------+-------------
725
+ f | 1
726
+ f | 1
727
+ (2 rows)
728
+
729
+ -- Neither check_a nor check_b are droppable from part_b
730
+ ALTER TABLE part_b DROP CONSTRAINT check_a;
731
+ ERROR: cannot drop inherited constraint "check_a" of relation "part_b"
732
+ ALTER TABLE part_b DROP CONSTRAINT check_b;
733
+ ERROR: cannot drop inherited constraint "check_b" of relation "part_b"
734
+ -- And dropping it from parted should leave no trace of them on part_b, unlike
735
+ -- traditional inheritance where they will be left behind, because they would
736
+ -- be local constraints.
737
+ ALTER TABLE parted DROP CONSTRAINT check_a, DROP CONSTRAINT check_b;
738
+ SELECT conislocal, coninhcount FROM pg_constraint WHERE conrelid = 'part_b'::regclass;
739
+ conislocal | coninhcount
740
+ ------------+-------------
741
+ (0 rows)
716
742
717
743
-- specify PARTITION BY for a partition
718
744
CREATE TABLE fail_part_col_not_found PARTITION OF parted FOR VALUES IN ('c') PARTITION BY RANGE (c);
@@ -757,9 +783,6 @@ drop table parted_collate_must_match;
757
783
b | integer | | not null | 1 | plain | |
758
784
Partition of: parted FOR VALUES IN ('b')
759
785
Partition constraint: ((a IS NOT NULL) AND (a = 'b'::text))
760
- Check constraints:
761
- "check_a" CHECK (length(a) > 0)
762
- "part_b_b_check" CHECK (b >= 0)
763
786
764
787
-- Both partition bound and partition key in describe output
765
788
\d+ part_c
@@ -771,8 +794,6 @@ Check constraints:
771
794
Partition of: parted FOR VALUES IN ('c')
772
795
Partition constraint: ((a IS NOT NULL) AND (a = 'c'::text))
773
796
Partition key: RANGE (b)
774
- Check constraints:
775
- "check_a" CHECK (length(a) > 0)
776
797
Partitions: part_c_1_10 FOR VALUES FROM (1) TO (10)
777
798
778
799
-- a level-2 partition's constraint will include the parent's expressions
@@ -784,8 +805,6 @@ Partitions: part_c_1_10 FOR VALUES FROM (1) TO (10)
784
805
b | integer | | not null | 0 | plain | |
785
806
Partition of: part_c FOR VALUES FROM (1) TO (10)
786
807
Partition constraint: ((a IS NOT NULL) AND (a = 'c'::text) AND (b IS NOT NULL) AND (b >= 1) AND (b < 10))
787
- Check constraints:
788
- "check_a" CHECK (length(a) > 0)
789
808
790
809
-- Show partition count in the parent's describe output
791
810
-- Tempted to include \d+ output listing partitions with bound info but
@@ -798,8 +817,6 @@ Check constraints:
798
817
a | text | | |
799
818
b | integer | | not null | 0
800
819
Partition key: LIST (a)
801
- Check constraints:
802
- "check_a" CHECK (length(a) > 0)
803
820
Number of partitions: 3 (Use \d+ to list them.)
804
821
805
822
\d hash_parted
0 commit comments