Thread: bug: ALTER TABLE ADD VIRTUAL GENERATED COLUMN with table rewrite

bug: ALTER TABLE ADD VIRTUAL GENERATED COLUMN with table rewrite

From
jian he
Date:
hi.


bug demo:
CREATE TABLE gtest20a (a int PRIMARY KEY, b int GENERATED ALWAYS AS (a
* 2) VIRTUAL);
ALTER TABLE gtest20a ADD COLUMN c float8 DEFAULT RANDOM() CHECK (b < 60);
ERROR:  no generation expression found for column number 2 of table
"pg_temp_17306"

issue is that
in ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap)
we need use existing (tab->relid) relation get the generated
expression, not use OIDNewHeap,
since we don't populate OIDNewHeap related generated expressions.

The attached patch fixes this issue.

Attachment

Re: bug: ALTER TABLE ADD VIRTUAL GENERATED COLUMN with table rewrite

From
Srinath Reddy
Date:
Hi,
I have applied the patch and verified,and patch LGTM.

Thanks and regards
Srinath Reddy Sadipiralla
EDB: https://www.enterprisedb.com/