From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: PetSerAl <petseral@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Re: Record returning function accept not matched columns declaration
Date: Thu, 29 Feb 2024 15:11:17 -0500
Message-ID: <2741768.1709237477@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwZ1-Ha1oHbHgveVgjNu6RWGQfVPNTO87y_=LxOmbyFBvA@mail.gmail.com>
References: <CAKygsHSerA1eXsJHR9wft3Gn3wfHQ5RfP8XHBzF70_qcrrRvEg@mail.gmail.com>
<CAKFQuwZ1-Ha1oHbHgveVgjNu6RWGQfVPNTO87y_=LxOmbyFBvA@mail.gmail.com>
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Thursday, February 29, 2024, PetSerAl <petseral@gmail.com> wrote:
>> postgres=# with a(b) as (values (row(1,2,3)))
>> postgres-# select * from a, coalesce(b) as c(d int,e int, f int)
>> postgres-# union all
>> postgres-# select * from a, nullif(b, null) as c(d int,e int, f int)
>> postgres-# union all
>> postgres-# select * from a, unnest(array[b]) as c(d int,e int, f int)
>> postgres-# union all
>> postgres-# select * from a, json_populate_record(b, null) as c(d int,e
>> int, f int); --expect OK
> My concern with all of this is accepting the specification of column
> definitions for functions that don’t return the record pseudo-type.
Hm? These cases all *do* return record, because that's what a.b is
typed as.
It looks to me like we broke these edge cases in refactoring.
v11 gives me the expected errors:
regression=# with a(b) as (values (row(1,2,3)))
select * from a, nullif(b, null) as c(d int,e int);
ERROR: function return row and query-specified return row do not match
DETAIL: Returned row contains 3 attributes, but query expects 2.
regression=# with a(b) as (values (row(1,2,3)))
select * from a, coalesce(b) as c(d int,e int);
ERROR: function return row and query-specified return row do not match
DETAIL: Returned row contains 3 attributes, but query expects 2.
v12 rejects the nullif example but not coalesce. v14 and up lets them
both by. I think the v14 change has to do with the function calls
having got flattened to constants, but I've not fingered the exact
culprit yet. I didn't look yet for the earlier behavioral change.
Even more amusing, since v14:
regression=# with a(b) as (values (row(1,2,3)))
select * from a, coalesce(b) as c(d int,e int,f int, g int);
server closed the connection unexpectedly
I think that Assert is just wrong and can be removed, though;
it doesn't seem to be guarding anything of interest.
regards, tom lane
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-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, petseral@gmail.com, pgsql-bugs@lists.postgresql.org
Subject: Re: Record returning function accept not matched columns declaration
In-Reply-To: <2741768.1709237477@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox