From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Magnus Persson <magnus(dot)e(dot)persson(at)gmail(dot)com> |
Cc: | PgSQL Novice <pgsql-novice(at)postgresql(dot)org> |
Subject: | Re: Passing result of multirow subquery to C function |
Date: | 2013-12-31 16:28:39 |
Message-ID: | 25595.1388507319@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Magnus Persson <magnus(dot)e(dot)persson(at)gmail(dot)com> writes:
> What I'm having issues figuring out is how to pass the results of a
> subquery to a function (if at all possible?):
> SELECT hello((SELECT name FROM names));
There's no direct way to do that; we have a notion of a "function
returning set", but not one of a "function accepting set".
The most straightforward thing is to reinterpret the requirement
as
SELECT hello(name) FROM names;
so that the function just deals with one name at a time.
You could also give the query to the function as a string and
have it execute the query internally (using SPI):
SELECT hello('SELECT name FROM names');
I find this to be a pretty bad design choice most of the time,
but sometimes there's no good alternative. There are precedents
in core PG, such as the ts_stat() functions.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Merlin Moncure | 2014-01-02 17:33:09 | Re: Passing result of multirow subquery to C function |
Previous Message | David Johnston | 2013-12-31 16:24:09 | Re: Passing result of multirow subquery to C function |