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