Returning a reference to a cursor from a function

From: "david williams" <dw_remote(at)hotmail(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Returning a reference to a cursor from a function
Date: 2002-09-12 18:12:37
Message-ID: DAV374EsURKQaJcrJf00000cd8c@hotmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

To anyone who can help me,

I am new at Postgresql and am having some problems.

I am trying to return a rowset from a function to the calling procedure.

Outside a function I have gotten this to work at the psql level.

-------------
BEGIN Work;
DECLARE Liahona CURSOR FOR Select * from users;
FETCH FORWARD ALL IN Liahona;
CLOSE Liahona;
COMMIT Work;
--------------

I went a stage further attempt to put this query into a function as such

--------------
CREATE FUNCTION getallusers() RETURN integer AS'
DECLARE
Liahona CURSOR FOR Select * from users;
BEGIN

FETCH FORWARD ALL IN Liahona;

CLOSE Liahona;
END;
'language 'plpgsql';

---------------
Followed by 'select getallusers();' for testing purposes.

I get the error:

ERROR during compile of getallusers near line 5
Parse error at or near "FORWARD"

I have tried creating RECORD type cursors but no luck.

Can anyone suggest how to do this.

I was referenced to this this through my discussion at dbforums.com.

http://dbforums.com/t499825.html

Thanks

!-------------------------------------!
David WilliamsGet more from the Web. FREE MSN Explorer download : http://explorer.msn.com

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2002-09-12 18:57:07 Re: Performance inside and outside view ( WAS Re: Select the
Previous Message Larry Rosenman 2002-09-12 17:49:21 Re: [SQL] Latitude / Longitude