@@ -703,16 +703,42 @@ CREATE TABLE part_b PARTITION OF parted (
703703) FOR VALUES IN ('b');
704704ERROR: column "b" specified more than once
705705CREATE 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)
708709) FOR VALUES IN ('b');
709710NOTICE: 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 ;
712713 conislocal | coninhcount
713714------------+-------------
714715 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)
716742
717743-- specify PARTITION BY for a partition
718744CREATE 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;
757783 b | integer | | not null | 1 | plain | |
758784Partition of: parted FOR VALUES IN ('b')
759785Partition 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)
763786
764787-- Both partition bound and partition key in describe output
765788\d+ part_c
@@ -771,8 +794,6 @@ Check constraints:
771794Partition of: parted FOR VALUES IN ('c')
772795Partition constraint: ((a IS NOT NULL) AND (a = 'c'::text))
773796Partition key: RANGE (b)
774- Check constraints:
775- "check_a" CHECK (length(a) > 0)
776797Partitions: part_c_1_10 FOR VALUES FROM (1) TO (10)
777798
778799-- 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)
784805 b | integer | | not null | 0 | plain | |
785806Partition of: part_c FOR VALUES FROM (1) TO (10)
786807Partition 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)
789808
790809-- Show partition count in the parent's describe output
791810-- Tempted to include \d+ output listing partitions with bound info but
@@ -798,8 +817,6 @@ Check constraints:
798817 a | text | | |
799818 b | integer | | not null | 0
800819Partition key: LIST (a)
801- Check constraints:
802- "check_a" CHECK (length(a) > 0)
803820Number of partitions: 3 (Use \d+ to list them.)
804821
805822\d hash_parted
0 commit comments