@@ -636,12 +636,22 @@ INSERT INTO gtest20 (a) VALUES (10); -- ok
636
636
INSERT INTO gtest20 (a) VALUES (30); -- violates constraint
637
637
ERROR: new row for relation "gtest20" violates check constraint "gtest20_b_check"
638
638
DETAIL: Failing row contains (30, virtual).
639
- ALTER TABLE gtest20 ALTER COLUMN b SET EXPRESSION AS (a * 100); -- violates constraint (currently not supported)
640
- ERROR: ALTER TABLE / SET EXPRESSION is not supported for virtual generated columns on tables with check constraints
641
- DETAIL: Column "b" of relation "gtest20" is a virtual generated column.
642
- ALTER TABLE gtest20 ALTER COLUMN b SET EXPRESSION AS (a * 3); -- ok (currently not supported)
643
- ERROR: ALTER TABLE / SET EXPRESSION is not supported for virtual generated columns on tables with check constraints
644
- DETAIL: Column "b" of relation "gtest20" is a virtual generated column.
639
+ ALTER TABLE gtest20 ALTER COLUMN b SET EXPRESSION AS (a * 100); -- violates constraint
640
+ ERROR: check constraint "gtest20_b_check" of relation "gtest20" is violated by some row
641
+ ALTER TABLE gtest20 ALTER COLUMN b SET EXPRESSION AS (a * 3); -- ok
642
+ --test no table rewrite happen
643
+ ALTER TABLE gtest20 ALTER COLUMN b SET EXPRESSION AS (a * 4), ADD COLUMN C int default 11;
644
+ SELECT pa.attnum,pa.attname,attmissingval
645
+ FROM pg_attribute pa
646
+ JOIN pg_attrdef patt ON pa.attrelid = patt.adrelid AND pa.attnum = patt.adnum
647
+ WHERE pa.attrelid = 'gtest20'::regclass
648
+ ORDER BY pa.attnum;
649
+ attnum | attname | attmissingval
650
+ --------+---------+---------------
651
+ 2 | b |
652
+ 3 | c | {11}
653
+ (2 rows)
654
+
645
655
CREATE TABLE gtest20a (a int PRIMARY KEY, b int GENERATED ALWAYS AS (a * 2) VIRTUAL);
646
656
INSERT INTO gtest20a (a) VALUES (10);
647
657
INSERT INTO gtest20a (a) VALUES (30);
@@ -973,6 +983,15 @@ SELECT tableoid::regclass, * FROM gtest_parent ORDER BY 1, 2, 3;
973
983
gtest_child3 | 09-13-2016 | 1 | 4
974
984
(3 rows)
975
985
986
+ --check constraint was validated based on each partitions's generation expression
987
+ ALTER TABLE gtest_parent ADD CONSTRAINT cc1 CHECK (f3 < 19); --error
988
+ ERROR: check constraint "cc1" of relation "gtest_child" is violated by some row
989
+ ALTER TABLE gtest_parent ADD CONSTRAINT cc1 CHECK (f3 < 66); --error
990
+ ERROR: check constraint "cc1" of relation "gtest_child2" is violated by some row
991
+ ALTER TABLE gtest_parent ADD CONSTRAINT cc1 CHECK (f3 <> 33); --error
992
+ ERROR: check constraint "cc1" of relation "gtest_child3" is violated by some row
993
+ ALTER TABLE gtest_parent ADD CONSTRAINT cc CHECK (f3 < 67); --ok
994
+ ALTER TABLE gtest_parent DROP CONSTRAINT cc;
976
995
-- alter generation expression of parent and all its children altogether
977
996
ALTER TABLE gtest_parent ALTER COLUMN f3 SET EXPRESSION AS (f2 * 2);
978
997
\d gtest_parent
0 commit comments