From: | "Merlin Moncure" <mmoncure(at)gmail(dot)com> |
---|---|
To: | "Kevin Murphy" <murphy(at)genome(dot)chop(dot)edu> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: function accepting and returning rows; how to avoid parentheses |
Date: | 2006-12-13 03:19:38 |
Message-ID: | b42b73150612121919hb66d4bcl10c32b1be2a0c05b@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 12/13/06, Kevin Murphy <murphy(at)genome(dot)chop(dot)edu> wrote:
> I'd like to have a function that acts as a row filter (that can
> optionally expand each row into multiple rows), but I don't know how to
> wangle this such that the output is not enclosed in parentheses, i.e.
> what I'm getting now is a single column of a composite type instead of
> multiple columns matching the original table layout.
>
> -- SQL front-end for filter function
> CREATE OR REPLACE FUNCTION explode(sometable) RETURNS SETOF sometable as $$
> SELECT * FROM foo($1) AS t;
> $$ LANGUAGE SQL STRICT IMMUTABLE;
>
> select explode(sometable.*) from sometable;
> explode
> -----------
> (A,1)
> (A,1)
> (B,2)
> (B,2)
functions defined in the sql language (as opposed to pl/pgsql) allow
you to call them without explicitly using from...if you want to
expand, just select from your result as you would expand any row
variable. basically, have you tried:
select (explode(sometable.*)).* from sometable;
merlin
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2006-12-13 03:41:19 | Re: Statement timeout not working on broken connections with active queries |
Previous Message | Michael Fuhr | 2006-12-13 03:18:30 | Re: resetting sequence to cur max value |