Re: ExecTypeSetColNames is fundamentally broken
Robert Haas <robertmhaas@gmail.com>
From: Robert Haas <robertmhaas@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2021-12-07T16:19:27Z
Lists: pgsql-hackers
On Mon, Dec 6, 2021 at 4:05 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Well, that was what I thought when I wrote bf7ca1587, but it leads
> to logical contradictions. Consider
>
> create table t (a int, b int);
>
> create function f(t) returns ... ;
>
> select f(t) from t;
>
> select f(t) from t(x,y);
>
> If we adopt the "rename for all purposes" interpretation, then
> the second SELECT must fail, because what f() is being passed is
> no longer of type t. If you ask me, that'll be a bigger problem
> for users than the change I'm proposing (quite independently of
> how hard it might be to implement). It certainly will break
> a behavior that goes back much further than bf7ca1587.
For me, the second SELECT does fail:
rhaas=# select f(t) from t(x,y);
ERROR: column "x" does not exist
LINE 1: select f(t) from t(x,y);
^
If it didn't fail, what would the behavior be? I suppose you could
make an argument for trying to match up the columns by position, but
if so this ought to work:
rhaas=# create table u(a int, b int);
CREATE TABLE
rhaas=# select f(u) from u;
ERROR: function f(u) does not exist
rhaas=# select f(u::t) from u;
ERROR: cannot cast type u to t
Matching columns by name can't work because the names don't match.
Matching columns by position does not work. So if that example
succeeds, the only real explanation is that we magically know that
we've still got a value of type t despite the user's best attempt to
decree otherwise. I know PostgreSQL sometimes ... does things like
that. I have no idea why anyone would consider it a desirable
behavior, though.
--
Robert Haas
EDB: http://www.enterprisedb.com
Commits
-
Don't bother to attach column name lists to RowExprs of named types.
- d7b5c071dd6a 15.0 landed
-
Revert applying column aliases to the output of whole-row Vars.
- ec62cb0aac5b 15.0 landed
- 5e144cc89b46 13.7 landed
- 205214c8b8cc 10.21 landed
- 1f5ef5ae0806 12.11 landed
- 1d072bd2030a 14.3 landed
- 13b54d1e0dde 11.16 landed