Database Reference
In-Depth Information
The first variant declares an unbound cursor which needs to be bound to a query at
OPEN time. The two remaining variants declare a cursor bound to a query.
Note
You can read a good technical overview on using cursors in PL/pgSQL functions
from the official PostgreSQL documentation at http://www.postgresql.org/docs/
current/static/plpgsql-cursors.html .
One thing to note about the documentation is that you don't really need to "return"
the cursor, at least not now.
The documentation states:
"The following example shows one way to return multiple cursors from a single func-
tion:
CREATE FUNCTION myfunc(refcursor, refcursor) RETURNS SETOF refcursor AS
$$
BEGIN
OPEN $1 FOR SELECT * FROM table_1;
RETURN NEXT $1;
OPEN $2 FOR SELECT * FROM table_2;
RETURN NEXT $2;
END;
$$ LANGUAGE plpgsql;
-- need to be in a transaction to use cursors.
BEGIN;
Search WWH ::




Custom Search