Thread: How to rename each field in ROW expression?
We can rename each field in VALUES clause: =# SELECT * FROM (VALUES(123, 'ABC', NULL)) AS t(a,b,c); a | b | c -----+-----+---123 | ABC | (1 row) But I cannot find ways for ROW expression to do the same thing: =# SELECT ROW(123, 'ABC', NULL) AS (a,b,c); ERROR: syntax error at or near "(" LINE 1: SELECT ROW(123, 'ABC', NULL) AS (a,b,c); ^ =# SELECT (ROW(123, 'ABC', NULL)).*; ERROR: record type has not been registered Is it possible to change names fields in ROW? We can use CREATE TYPE AS on ahead, but I'd like to change names of ROW expression in ad-hoc queries. -- Itagaki Takahiro
Itagaki Takahiro <itagaki.takahiro@gmail.com> writes: > Is it possible to change names fields in ROW? > We can use CREATE TYPE AS on ahead, but I'd like to > change names of ROW expression in ad-hoc queries. Why? It's an anonymous type, you shouldn't care about names. If you do, make a real named rowtype. regards, tom lane
On Tue, Nov 16, 2010 at 00:18, Tom Lane <tgl@sss.pgh.pa.us> wrote: > Why? It's an anonymous type, you shouldn't care about names. > If you do, make a real named rowtype. If so, we cannot extract any fields in an anonymous type, right? We cannot lookup fields with (an anonymous type).name because the fields have no names. =# SELECT (ROW(123, 'ABC', NULL)).*; ERROR: record type has not been registered -- Itagaki Takahiro