agora inbox for pgsql-committers@postgresql.org
help / color / mirror / Atom feedFrom: Dean Rasheed <dean.a.rasheed@gmail.com>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix expansion of EXCLUDED virtual generated columns.
Date: Wed, 22 Apr 2026 08:07:15 +0000
Message-ID: <E1wFSc6-0027yQ-32@gemulon.postgresql.org> (raw)
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(+)
view thread (2+ messages)
Message-ID: <E1wFSc6-0027yQ-32@gemulon.postgresql.org>
Permalink: ../E1wFSc6-0027yQ-32@gemulon.postgresql.org/
Also on: postgresql.org/message-id/E1wFSc6-0027yQ-32@gemulon.postgresql.org
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: dean.a.rasheed@gmail.com, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Fix expansion of EXCLUDED virtual generated columns.
In-Reply-To: <E1wFSc6-0027yQ-32@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox