bug: ALTER TABLE ADD VIRTUAL GENERATED COLUMN with table rewrite

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Cc: Peter <peter(at)eisentraut(dot)org>
Subject: bug: ALTER TABLE ADD VIRTUAL GENERATED COLUMN with table rewrite
Date: 2025-02-27 15:00:51
Message-ID: CACJufxEJ=FoajabWXjszo_yrQeKSxdZ87KJqBW373rSbajKGAA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 Content-Type Size
v1-0001-fix-ALTER-TABLE-ADD-VIRTUAL-GENERATED-COLUMN-when.patch text/x-patch 3.4 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Gilles Darold 2025-02-27 15:33:31 Re: proposal: plpgsql, new check for extra_errors - strict_expr_check
Previous Message Greg Sabino Mullane 2025-02-27 14:52:30 Re: pg_dump, pg_dumpall, pg_restore: Add --no-policies option