usring CURSORS within functions

From: "SunMie Won" <sunmiewon(at)yahoo(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: usring CURSORS within functions
Date: 2001-11-18 19:12:02
Message-ID: KJEGKKOJCBGKOFEHHBIKGEFGCDAA.sunmiewon@yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Any tips on how to use a cursor within a function?
Does the DECLARE come after the BEGIN ( as all the
documentation suggests) or in the typical place for
declarations (after AS and before BEGIN). I have tried
both places and when running the function, get the
following error:

ERROR: parse error at or near CURSOR

Below is the syntax for my function:
CREATE FUNCTION "fnc_testcursor"("int4") RETURNS
"int4" AS
'DECLARE c_seating CURSOR FOR SELECT id_seat FROM
tbl_seating WHERE id_order = 0;
BEGIN FETCH 1 FROM c_seating;
CLOSE c_seating;
END;'
LANGUAGE 'plpgsql';

OR version 2:

CREATE FUNCTION "fnc_testcursor"("int4") RETURNS
"int4"
AS
'
BEGIN
DECLARE c_seating CURSOR FOR SELECT id_seat FROM
tbl_seating WHERE id_order = 0;
FETCH 1 FROM c_seating;
CLOSE c_seating;
END;'
LANGUAGE 'plpgsql';

Both functions return the same error when called.
Thanks in advance-
SunMie Won

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-11-18 19:43:15 Re: usring CURSORS within functions
Previous Message Raoul Callaghan 2001-11-18 17:17:04 Postmaster on OSX 10.1.1 what's the deal?