Thanks for the update!

+-- a child with two parents cannot have its expression changed through one
+CREATE TABLE gtesty (a int, b int GENERATED ALWAYS AS (a * 2) VIRTUAL);
+CREATE TABLE gtestz (a int, b int GENERATED ALWAYS AS (a * 2) VIRTUAL);
+CREATE TABLE gtestyz () INHERITS (gtesty, gtestz);
+NOTICE:  merging multiple inherited definitions of column "a"
+NOTICE:  merging multiple inherited definitions of column "b"
+ALTER TABLE gtesty ALTER COLUMN b SET EXPRESSION AS (a * 3);  -- error

But it can with a combined alter:

CREATE TABLE q (a int, b int GENERATED ALWAYS AS (nullif(a, 1))
VIRTUAL NOT NULL);
CREATE TABLE p (a int);
CREATE TABLE c () INHERITS (p, q);
ALTER TABLE p ADD COLUMN b int GENERATED ALWAYS AS (nullif(a, 1)) VIRTUAL,
              ALTER COLUMN b SET EXPRESSION AS (a);      -- accepted

Also, in the above example if we try to alter the child instead we get:

ALTER TABLE gtestyz ALTER COLUMN b SET EXPRESSION AS (a * 3);
-- ERROR:  cannot alter inherited column "b"
-- HINT:  Alter the generation expression of the top-level parent table instead.

But that hint won't work, as the testcase shows.


Reply via email to