Fix ALTER TABLE ADD VIRTUAL GENERATED COLUMN when table rewrite
Peter Eisentraut <peter@eisentraut.org>
Fix ALTER TABLE ADD VIRTUAL GENERATED COLUMN when table rewrite 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" In ATRewriteTable, the variable OIDNewHeap (if valid) corresponding pg_attrdef default expression entry was not populated. So OIDNewHeap cannot be used to call expand_generated_columns_in_expr or build_generation_expression. Therefore in ATRewriteTable, we can only use the existing relation to expand the generated expression. Author: jian he <jian.universality@gmail.com> Reviewed-by: Srinath Reddy <srinath2133@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/CACJufxEJ%3DFoajabWXjszo_yrQeKSxdZ87KJqBW373rSbajKGAA%40mail.gmail.com
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/commands/tablecmds.c | modified | +1 −1 |
| src/test/regress/expected/generated_stored.out | modified | +4 −0 |
| src/test/regress/expected/generated_virtual.out | modified | +4 −0 |
| src/test/regress/sql/generated_stored.sql | modified | +3 −0 |
| src/test/regress/sql/generated_virtual.sql | modified | +3 −0 |
Discussion
- bug: ALTER TABLE ADD VIRTUAL GENERATED COLUMN with table rewrite 3 messages · 2025-02-27 → 2025-03-04