bug: ALTER TABLE ADD VIRTUAL GENERATED COLUMN with table rewrite
jian he <jian.universality@gmail.com>
From: jian he <jian.universality@gmail.com>
To: PostgreSQL-development <pgsql-hackers@postgresql.org>
Cc: Peter <peter@eisentraut.org>
Date: 2025-02-27T15:00:51Z
Lists: pgsql-hackers
Attachments
- v1-0001-fix-ALTER-TABLE-ADD-VIRTUAL-GENERATED-COLUMN-when.patch (text/x-patch) patch v1-0001
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.
Commits
-
Fix ALTER TABLE ADD VIRTUAL GENERATED COLUMN when table rewrite
- f011acdd61fc 18.0 landed