On Fri, Sep 19, 2014 at 9:26 AM, Merlin Moncure <mmonc...@gmail.com> wrote:
> On Thu, Sep 18, 2014 at 5:22 PM, Hannu Krosing <ha...@2ndquadrant.com> wrote:
>> Though it would be even nicer to have fully in-line type definition
>>
>> SELECT (tup).* FROM
>>   (
>>     SELECT CASE WHEN .. THEN ROW(1,2,3)::(a int, b text, c int2)
>>             WHEN .. THEN ROW(2,3,4)
>>             ELSE ROW (3,4,5) END AS tup
>>     FROM ..
>>   ) ss
>
> +1.   Workaround at present (which I mostly use during json serialization) is:
>
> SELECT (tup).* FROM
>   (
>     SELECT CASE WHEN .. THEN
>                (SELECT q FROM (SELECT 1, 2, 3) q)
>             WHEN .. THEN
>                (SELECT q FROM (SELECT 2, 3, 4) q)
>             ELSE (SELECT q FROM (SELECT 3, 4, 5) q)
>             END AS tup
>     FROM ..
>   ) ss

actually, this trick *only* works during json serialization -- it
allows control over the column names that row() masks over.  trying to
expand (tup).* still gives the dreaded "ERROR:  record type has not
been registered".  That's because this works:

select (q).* from (select 1 as a, 2 as b) q;

but this doesn't:

select ((select q from (select a,b) q)).* from (select 1 as a, 2 as b) q;

merlin


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to