From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
Cc: | "Kidd, David M" <d(dot)kidd(at)imperial(dot)ac(dot)uk>, "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: Cursor names in a self-nested function |
Date: | 2011-08-18 16:15:33 |
Message-ID: | 5483.1313684133@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> writes:
> you can use a refcursor type
> http://developer.postgresql.org/pgdocs/postgres/plpgsql-cursors.html
It would suffice to explicitly set mycursor to null before doing the
OPEN, thus instructing the system to assign a unique cursor name.
CREATE FUNCTION test(id integer) RETURNS TEXT AS
$BODY$
DECLARE
mycursor CURSOR FOR SELECT * FROM int4_tbl WHERE f1 > id;
newid INTEGER;
out TEXT;
BEGIN
out := id::text || ' ';
mycursor := null;
OPEN mycursor;
raise notice 'mycursor = %', mycursor; -- debug
LOOP
FETCH mycursor INTO newid;
EXIT WHEN newid IS NULL;
out := out || test (newid);
END LOOP;
RETURN out;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Mikola Rose | 2011-08-19 19:08:09 | (pgsql8.4) DATA Corruption |
Previous Message | Pavel Stehule | 2011-08-18 15:36:07 | Re: Cursor names in a self-nested function |