Re: passing cursors from one PL function to another

Поиск
Список
Период
Сортировка
От Merlin Moncure
Тема Re: passing cursors from one PL function to another
Дата
Msg-id CAHyXU0xu=J3o+JejAT8HzPwdorRu3g+q1JSmtgS2-K1zC6Ma1w@mail.gmail.com
обсуждение исходный текст
Ответ на passing cursors from one PL function to another  (Martín Marqués <martin.marques@gmail.com>)
Ответы Re: passing cursors from one PL function to another
Список pgsql-general
2011/8/25 Martín Marqués <martin.marques@gmail.com>:
> CREATE OR REPLACE FUNCTION prueba_cursor(codigo integer, curCursor refcursor)
>   RETURNS SETOF refcursor AS
> $BODY$
> DECLARE
>       cur alias for $2;
> BEGIN
>       PERFORM mpf.ConstruyeCursorDesdeQuery('cur' ,'SELECT * from
> tab1 WHERE field < 11000');
> END;
> $BODY$
> LANGUAGE 'plpgsql' VOLATILE
> COST 100
> ROWS 1000;
>
> CREATE OR REPLACE FUNCTION construyecursordesdequery(refcursor, query text)
>   RETURNS SETOF refcursor AS
> $BODY$
> BEGIN
>   OPEN $1 FOR Select * from tab1 where field < 11000;
>   RAISE NOTICE '%', $1;
>   RETURN NEXT $1;
> END;
> $BODY$
> LANGUAGE 'plpgsql' VOLATILE
> COST 100
> ROWS 1000;
>
> begin;
> select * from prueba_cursor4(1, 'h');
> end;

you pretty much had it.
> select * from prueba_cursor4(1, 'h');
should be
> select * from prueba_cursor(1, 'h');

after that, but inside the transaction, you can just do:
fetch all from 'cur';

note neither of your functions need to return setof fwict.  you are
returning one cursor, not a set of them.

merlin

В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: pg_restore with -j fails (works without -j option)
Следующее
От: Ondrej Ivanič
Дата:
Сообщение: Re: Sort Method: external merge