From: | Benedikt Grundmann <benedikt(dot)grundmann(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Expression to construct a anonymous record with named columns? |
Date: | 2012-09-20 18:36:29 |
Message-ID: | CAMr3DCMJfbxFAK08rpOZSoGKNMCA+fM+YO6X=RkTeczrX_8sLQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Aleksey Tsalolikhin | 2012-09-20 19:20:55 | Why do I have holes in my pages? |
Previous Message | John R Pierce | 2012-09-20 18:33:09 | Re: Using psql -f to load a UTF8 file |