Re: Anonymous code block with parameters

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Hannu Krosing <hannu(at)2ndquadrant(dot)com>
Cc: Marko Tiikkaja <marko(at)joh(dot)to>, Vik Fearing <vik(dot)fearing(at)dalibo(dot)com>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>, Craig Ringer <craig(at)2ndquadrant(dot)com>, Kalyanov Dmitry <kalyanov(dot)dmitry(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Anonymous code block with parameters
Date: 2014-09-19 18:20:09
Message-ID: CAHyXU0zrox1t2C5M29Fz1h_bzAddhMYAOdaEr-us6Y14xyGyUw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Sep 19, 2014 at 9:26 AM, Merlin Moncure <mmoncure(at)gmail(dot)com> wrote:
> On Thu, Sep 18, 2014 at 5:22 PM, Hannu Krosing <hannu(at)2ndquadrant(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Zhaomo Yang 2014-09-19 18:28:10 Re: A mechanism securing web applications in DBMS
Previous Message Peter Geoghegan 2014-09-19 18:05:32 Re: B-Tree support function number 3 (strxfrm() optimization)