Re: Reject wholerow references where ColumnRef is forbidden

From: Paul A Jungwirth <pj(at)illuminatedcomputing(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>
Subject: Re: Reject wholerow references where ColumnRef is forbidden
Date: 2026-11-04 04:11:41
Message-ID: CA+renyU0yPW9H1sAOK_Jm2Evxw_8a5vKaRDpjPCX9eAXm2m2ww@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, Oct 31, 2026 at 1:24 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Good catch, but I really don't like this choice:
>
> > Actually instead of calling it from ExpandColumnRefStar, I'm calling it
> > from (one of) its callers, since it isn't always necessary.
>
> That's a recipe for future errors of omission; if someone adds another
> call of ExpandColumnRefStar, they might copy the wrong pattern.
>
> Another problem is that I'm not sure that every case of "something.*"
> produces Vars; foo().* would not, for example. It might be better to
> push the check down to someplace like expandNSItemVars.

Here is a patch that calls checkColumnRefAllowed from expandNSItemVars
instead. It allows foo().* but forbids (ROW(t.*)).f1.

I've included an optional (squashable) second patch that also calls it
from ExpandColumnRefStar, so that even when the table name can't be
resolved, we still get "cannot use column reference" instead of
"missing FROM-clause entry". That seems like the more fundamental
problem, and for defaults & partitions there is no FROM clause anyway.

I've also attached separate patch files for v14/15, since
expandNSItemVars has no pstate. I'm calling checkColumnRefAllowed from
its callers instead to preserve the ABI.

Yours,

--
Paul ~{:-)
pj(at)illuminatedcomputing(dot)com

Attachment Content-Type Size
v2-0002-Improve-error-message-expanding-foo.-in-invalid-l.patch text/x-patch 4.7 KB
v2-0001-Reject-whole-row-references-where-column-referenc.patch text/x-patch 12.0 KB
nocfbot-v2-0001-Reject-whole-row-references-where-column-referenc.patch text/x-patch 13.5 KB
nocfbot-v2-0002-Improve-error-message-expanding-foo.-in-invalid-l.patch text/x-patch 4.7 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Paul A Jungwirth 2026-11-04 04:27:29 Re: Fix trigger memory leak
Previous Message shveta malik 2026-11-04 03:33:13 Re: BUG? Unpublished generated columns are reported "missing" by the subscription