I have a doubt about how a function returns a reference to a cursor in PostgreSQL. I have the following query :
CREATE FUNCTION reffunc(refcursor) RETURNS refcursor AS '
BEGIN
OPEN $1 FOR SELECT col FROM test;
RETURN $1;
END;
' LANGUAGE plpgsql;
BEGIN;
SELECT reffunc('funccursor');
FETCH ALL IN funccursor;
COMMIT;
Does this function return a reference to a cursor ? If not, how can I modify it to return a reference to a cursor ?
A refcursor
variable contains the name of a cursor, a data structure that holds the active query.
See the documentation.
So yes, it is a reference to a cursor.