On Fri, May 16, 2025 at 1:00 PM Alexander Lakhin <exclus...@gmail.com> wrote:
> I've discovered yet another way to trigger that error:
> create table vt (a int, b int generated always as (a * 2), c int);
> insert into vt values(1);
> alter table vt alter column c type bigint using b + c;
>
> ERROR:  XX000: unexpected virtual generated column reference
> LOCATION:  CheckVarSlotCompatibility, execExprInterp.c:2410

Thank you for the report.  It seems that we fail to expand references
to virtual generated columns in the NewColumnValues expression when
altering tables.  We might be able to fix it by:

@@ -6203,7 +6203,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap)
        NewColumnValue *ex = lfirst(l);

        /* expr already planned */
-       ex->exprstate = ExecInitExpr((Expr *) ex->expr, NULL);
+       ex->exprstate = ExecInitExpr((Expr *)
expand_generated_columns_in_expr((Node *) ex->expr, oldrel, 1), NULL);

Thanks
Richard


Reply via email to