Re: ExecTypeSetColNames is fundamentally broken

Поиск
Список
Период
Сортировка
От Robert Haas
Тема Re: ExecTypeSetColNames is fundamentally broken
Дата
Msg-id CA+Tgmoa2Fm+4eDb6O4NFzA-u78k2Wa0-V48qimSVgBbCF2MvDg@mail.gmail.com
обсуждение исходный текст
Ответ на Re: ExecTypeSetColNames is fundamentally broken  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: ExecTypeSetColNames is fundamentally broken  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: AW: Assorted improvements in pg_dump
Следующее
От: Tom Lane
Дата:
Сообщение: Re: MSVC SSL test failure