Is there a way to construct write an expression that constructs a record with with named columns. Specificially without the need for a corresponding named type.
Creates a unnamed record type. And indeed it is for example not possible to expand it:
postgres=# select (row(1, 2, 3)).*; ERROR: record type has not been registered
On the other hand columns listed in a multi column select clause create a row type that is expandable and named: postgres=# select ((bar.*).x).a from (select x from (select 1 as a, 2 as b) x) bar; a --- 1 (1 row)
But it seems to not be possible to do so without a from clause:
postgres=# select ((select x from (select 1 as a, 2 as b) x)).a; ERROR: syntax error at or near "." LINE 1: select ((select x from (select 1 as a, 2 as b) x)).a; ^ postgres=# select ((select x from (select 1 as a, 2 as b) x)).*; ERROR: syntax error at or near "." LINE 1: select ((select x from (select 1 as a, 2 as b) x)).*;
So named anonymous records / row types seem to be strangely second class. Can somebody clarify the restrictions and rationale or even better show a way to do the equivalent of (made up syntax ahead):