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 14:26:17
Message-ID: CAHyXU0xgVuE8BsUWTE3nDEXGyGQs6xxw=eZf5WhTvt6j3Wh=_w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

If you're talking in line type definitions (which is kinda off topic)
though, it'd be nice to consider:

* nested type definition:
create type foo_t as
(
a text,
b int,
bars bar_t[] as
(
c int,
d text
),
baz baz_t as
(
e text,
f text
)
);

* ...and recursive type references (not being able to recursively
serialize json is a major headache)
create type foo_t as
(
path text,
children foo_t[]
);

merlin

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2014-09-19 14:42:21 Re: [REVIEW] Re: Compression of full-page-writes
Previous Message Dev Kumkar 2014-09-19 14:09:05 Re: pg_multixact issues