agora inbox for pgsql-committers@postgresql.orghelp / color / mirror / Atom feed
pgsql: Fix expansion of EXCLUDED virtual generated columns. 2+ messages / 1 participants [nested] [flat]
* pgsql: Fix expansion of EXCLUDED virtual generated columns. @ 2026-04-22 08:07 Dean Rasheed <dean.a.rasheed@gmail.com> 0 siblings, 0 replies; 2+ messages in thread From: Dean Rasheed @ 2026-04-22 08:07 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix expansion of EXCLUDED virtual generated columns. If the SET or WHERE clause of an INSERT ... ON CONFLICT command references EXCLUDED.col, where col is a virtual generated column, the column was not properly expanded, leading to an "unexpected virtual generated column reference" error, or incorrect results. The problem was that expand_virtual_generated_columns() would expand virtual generated columns in both the SET and WHERE clauses and in the targetlist of the EXCLUDED pseudo-relation (exclRelTlist). Then fix_join_expr() from set_plan_refs() would turn the expanded expressions in the SET and WHERE clauses back into Vars, because they would be found to match the expression entries in the indexed tlist produced from exclRelTlist. To fix this, arrange for expand_virtual_generated_columns() to not expand virtual generated columns in exclRelTlist. This forces set_plan_refs() to resolve generation expressions in the query using non-virtual columns, as required by the executor. In addition, exclRelTlist now always contains only Vars. That was something already claimed in a couple of existing comments in the planner, which relied on that fact to skip some processing, though those did not appear to constitute active bugs. Reported-by: Satyanarayana Narlapuram <satyanarlapuram@gmail.com> Author: Satyanarayana Narlapuram <satyanarlapuram@gmail.com> Author: Dean Rasheed <dean.a.rasheed@gmail.com> Discussion: https://postgr.es/m/CAHg+QDf7wTLz_vqb1wi1EJ_4Uh+Vxm75+b4c-Ky=6P+yOAHjbQ@mail.gmail.com Backpatch-through: 18 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/783425175809c91f702dec72b0d52cab7692f1a9 Modified Files -------------- src/backend/optimizer/prep/prepjointree.c | 19 ++++++++++ src/test/regress/expected/generated_virtual.out | 48 +++++++++++++++++++++++++ src/test/regress/sql/generated_virtual.sql | 25 +++++++++++++ 3 files changed, 92 insertions(+) ^ permalink raw reply [nested|flat] 2+ messages in thread
* pgsql: Fix expansion of EXCLUDED virtual generated columns. @ 2026-04-22 08:07 Dean Rasheed <dean.a.rasheed@gmail.com> 0 siblings, 0 replies; 2+ messages in thread From: Dean Rasheed @ 2026-04-22 08:07 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix expansion of EXCLUDED virtual generated columns. If the SET or WHERE clause of an INSERT ... ON CONFLICT command references EXCLUDED.col, where col is a virtual generated column, the column was not properly expanded, leading to an "unexpected virtual generated column reference" error, or incorrect results. The problem was that expand_virtual_generated_columns() would expand virtual generated columns in both the SET and WHERE clauses and in the targetlist of the EXCLUDED pseudo-relation (exclRelTlist). Then fix_join_expr() from set_plan_refs() would turn the expanded expressions in the SET and WHERE clauses back into Vars, because they would be found to match the expression entries in the indexed tlist produced from exclRelTlist. To fix this, arrange for expand_virtual_generated_columns() to not expand virtual generated columns in exclRelTlist. This forces set_plan_refs() to resolve generation expressions in the query using non-virtual columns, as required by the executor. In addition, exclRelTlist now always contains only Vars. That was something already claimed in a couple of existing comments in the planner, which relied on that fact to skip some processing, though those did not appear to constitute active bugs. Reported-by: Satyanarayana Narlapuram <satyanarlapuram@gmail.com> Author: Satyanarayana Narlapuram <satyanarlapuram@gmail.com> Author: Dean Rasheed <dean.a.rasheed@gmail.com> Discussion: https://postgr.es/m/CAHg+QDf7wTLz_vqb1wi1EJ_4Uh+Vxm75+b4c-Ky=6P+yOAHjbQ@mail.gmail.com Backpatch-through: 18 Branch ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/cf38dedf693a17f9317d8ed85ab7468afebf8cbf Modified Files -------------- src/backend/optimizer/prep/prepjointree.c | 19 ++++++++++ src/test/regress/expected/generated_virtual.out | 48 +++++++++++++++++++++++++ src/test/regress/sql/generated_virtual.sql | 25 +++++++++++++ 3 files changed, 92 insertions(+) ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2026-04-22 08:07 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-04-22 08:07 pgsql: Fix expansion of EXCLUDED virtual generated columns. Dean Rasheed <dean.a.rasheed@gmail.com> 2026-04-22 08:07 pgsql: Fix expansion of EXCLUDED virtual generated columns. Dean Rasheed <dean.a.rasheed@gmail.com>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox