Magnus Persson <magnus.e.persson@gmail.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