Re: Stored procedures vs Functions - Mailing list pgsql-general

From Tom Lane
Subject Re: Stored procedures vs Functions
Date
Msg-id 21224.1008988750@sss.pgh.pa.us
Whole thread Raw
In response to Re: Stored procedures vs Functions  (Jeff Davis <list-pgsql-general@dynworks.com>)
List pgsql-general
Jeff Davis <list-pgsql-general@dynworks.com> writes:
> I was trying it out and I had no problem creating the
> function. However, if I have a function that returns a reference to a
> cursor, how would I got about fetching form that cursor reference? I
> guess my question is: with SQL, how do I turn the cursor reference
> into an actual cursor from which I may fetch records?

I don't think you can do it in pure SQL; the facility is really designed
for passing back a cursor name to another plpgsql function, or an
application that is able to substitute the returned cursor name into
a query.  Given

> jdavis=# begin;
> BEGIN
> jdavis=# select f1();
>          f1
> --------------------
>  <unnamed cursor 5>
> (1 row)

you need to do

    fetch 1 from "<unnamed cursor 5>";

psql has a primitive variable-substitution facility, but I don't think
that's quite smart enough to handle this.  It'd be easy enough in almost
any application programming language, however.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Database tuning
Next
From: Tom Lane
Date:
Subject: Re: udp port