plpgsql - fetching from returned cursors

Started by k|pabout 23 years ago2 messagesgeneral
Jump to latest
#1k|p
m.e.meulemans@student.utwente.nl

Is something like this possible?
Because the way I wrote it now, nothing is FOUND from the FETCH and the loop is
exited.

CREATE OR REPLACE FUNCTION test(integer) RETURNS integer AS '
DECLARE
my_cursor refcursor;
my_row row;
BEGIN
my_cursor = get_refcursor($1);

LOOP
FETCH my_cursor INTO my_row;
EXIT WHEN NOT FOUND;
RAISE DEBUG ''id: %'', my_row.id;
END LOOP;
END;
' LANGUAGE 'plpgsql';

Thanks,
kip

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: k|p (#1)
Re: plpgsql - fetching from returned cursors

"k|p" <m.e.meulemans@student.utwente.nl> writes:

Is something like this possible?
Because the way I wrote it now, nothing is FOUND from the FETCH and the loop is
exited.

It works for me ... or at least it did after I changed "my_row" to type
RECORD, added a RETURN at the end, and made the RAISE be RAISE NOTICE
so I could actually see some output.

regards, tom lane