Re: Stored procedures vs Functions

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jeff Davis <list-pgsql-general(at)dynworks(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Stored procedures vs Functions
Date: 2001-12-22 02:39:10
Message-ID: 21224.1008988750@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jeff Davis <list-pgsql-general(at)dynworks(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-12-22 02:47:08 Re: udp port
Previous Message Tom Lane 2001-12-22 02:28:22 Re: Database tuning