bug: ALTER TABLE ADD VIRTUAL GENERATED COLUMN with table rewrite - Mailing list pgsql-hackers

From jian he
Subject bug: ALTER TABLE ADD VIRTUAL GENERATED COLUMN with table rewrite
Date
Msg-id CACJufxEJ=FoajabWXjszo_yrQeKSxdZ87KJqBW373rSbajKGAA@mail.gmail.com
Whole thread Raw
Responses Re: bug: ALTER TABLE ADD VIRTUAL GENERATED COLUMN with table rewrite
List pgsql-hackers
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

pgsql-hackers by date:

Previous
From: Greg Sabino Mullane
Date:
Subject: Re: pg_dump, pg_dumpall, pg_restore: Add --no-policies option
Next
From: Gilles Darold
Date:
Subject: Re: proposal: plpgsql, new check for extra_errors - strict_expr_check