Re: Passing result of multirow subquery to C function - Mailing list pgsql-novice

From Tom Lane
Subject Re: Passing result of multirow subquery to C function
Date
Msg-id 25595.1388507319@sss.pgh.pa.us
Whole thread Raw
In response to Passing result of multirow subquery to C function  (Magnus Persson <magnus.e.persson@gmail.com>)
List pgsql-novice
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


pgsql-novice by date:

Previous
From: David Johnston
Date:
Subject: Re: Passing result of multirow subquery to C function
Next
From: Merlin Moncure
Date:
Subject: Re: Passing result of multirow subquery to C function