Re: Record returning function accept not matched columns declaration
PetSerAl <petseral@gmail.com>
From: PetSerAl <petseral@gmail.com>
To: "David G. Johnston" <david.g.johnston@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, "pgsql-bugs@lists.postgresql.org" <pgsql-bugs@lists.postgresql.org>
Date: 2024-02-29T22:01:31Z
Lists: pgsql-bugs
postgres=# with a(b) as (values (row(1,2,3)))
postgres-# select * from a, coalesce(b);
ERROR: a column definition list is required for functions returning "record"
LINE 2: select * from a, coalesce(b);
^
postgres=#
postgres=# with a(b) as (values (row(1,2,3)))
postgres-# select * from a, nullif(b, null);
ERROR: a column definition list is required for functions returning "record"
LINE 2: select * from a, nullif(b, null);
^
postgres=#
postgres=# with a(b) as (values (row(1,2,3)))
postgres-# select * from a, unnest(array[b]);
ERROR: a column definition list is required for functions returning "record"
LINE 2: select * from a, unnest(array[b]);
^
postgres=#
postgres=# with a(b) as (values (row(1,2,3)))
postgres-# select * from a, json_populate_record(b, null);
ERROR: a column definition list is required for functions returning "record"
LINE 2: select * from a, json_populate_record(b, null);
^
postgres=#
It seems PostgreSQL does not care about function being polymorphic,
but only about return type being "record". It explicitly require
column definition list in all this cases.
пт, 1 мар. 2024 г. в 00:32, David G. Johnston <david.g.johnston@gmail.com>:
>
> On Thu, Feb 29, 2024 at 1:11 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>
>> "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.
>
>
> I strongly dislike the seemingly overloaded terminology in this area. Namely I was trying to distinguish these two example function signatures.
>
> json_populate_record ( base anyelement, from_json json ) → anyelement
> jsonb_to_record ( jsonb ) → record
>
> Polymorphic functions do not require a column definition list. The non-polymorphic function signature does require the column definition list. That we accept a column definition list in the polymorphic case is settled code but seems like it led to this bug.
>
> David J.
Commits
-
Fix type-checking of RECORD-returning functions in FROM.
- d769f9d97feb 13.15 landed
- a595c3075fb4 14.12 landed
- 466376c9f848 12.19 landed
- 3b671dcf53d1 15.7 landed
- 2ed8f9a01e74 17.0 landed
- 1b3029be5df0 16.3 landed