Функция plpgsql с курсором
CREATE OR REPLACE FUNCTION procedure_cursor() RETURNS VOID AS $$ DECLARE ref_cursor REFCURSOR; name TEXT; age INTEGER; BEGIN OPEN ref_cursor FOR SELECT * FROM customers; LOOP FETCH ref_cursor INTO name, age; EXIT WHEN NOT FOUND; RAISE NOTICE '%', name; RAISE NOTICE '%', age; END LOOP; CLOSE ref_cursor; END; $$ LANGUAGE plpgsql;