Re: Record returning function accept not matched columns declaration
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: "David G. Johnston" <david.g.johnston@gmail.com>
Cc: PetSerAl <petseral@gmail.com>,
"pgsql-bugs@lists.postgresql.org" <pgsql-bugs@lists.postgresql.org>
Date: 2024-03-06T20:09:09Z
Lists: pgsql-bugs
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> with a(b) as (values (row(1,2,3)))
> select (a.b).* from a;
> ERROR: record type has not been registered
I looked into this case. The failure occurs when the parser tries
to expand the ".*" notation into separate output columns, as required
per SQL spec. All it has is a Var of type RECORD referencing the
VALUES RTE entry, so it has to fail.
In the specific example given here, you could imagine drilling down
into the VALUES and figuring out what concrete rowtype the RECORD
value will have at runtime, but I'm not excited about going there.
There are too many cases where it wouldn't work.
Note that as long as you don't need parse-time expansion of the
record, it works:
=# with a(b) as (values (row(1,2,3)))
select a.b from a;
b
---------
(1,2,3)
(1 row)
I pushed the patch for the original problem. After debating with
myself I concluded that back-patching it was probably less risky
than not back-patching, so I did that.
regards, tom lane
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