Expression to construct a anonymous record with named columns?

Поиск
Список
Период
Сортировка
От Benedikt Grundmann
Тема Expression to construct a anonymous record with named columns?
Дата
Msg-id CAMr3DCMJfbxFAK08rpOZSoGKNMCA+fM+YO6X=RkTeczrX_8sLQ@mail.gmail.com
обсуждение исходный текст
Ответы Re: Expression to construct a anonymous record with named columns?  (Alban Hertroys <haramrae@gmail.com>)
Список pgsql-general
Hello,

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.

That is

postgres=# select row(1, 2, 3);
   row  
---------
 (1,2,3)
(1 row)

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):

select row(1 as a, 2 as b);

Cheers,

Bene

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

Предыдущее
От: Chris Angelico
Дата:
Сообщение: Re: Using psql -f to load a UTF8 file
Следующее
От: Alan Millington
Дата:
Сообщение: Re: Using psql -f to load a UTF8 file