Re: passing cursors from one PL function to another

From: Martín Marqués <martin(dot)marques(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: passing cursors from one PL function to another
Date: 2011-08-26 00:49:59
Message-ID: CABeG9LtaV8MQJm2Y6cV8LuZNLfiGybx5VBKRkuvxP=CEUMLE_g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Sorry, pressed send. :-(

I have, as the functions show below, 2 functions that call one
another, passing a cursor (AFAIK). The problem is that it doesn't
work, giving errors when executing the last SELECT.

Is it posible to pass a cursor from one function to another?

El día 25 de agosto de 2011 21:46, Martín Marqués
<martin(dot)marques(at)gmail(dot)com> escribió:
> 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;
>
>
>
> --
> Martín Marqués
> select 'martin.marques' || '@' || 'gmail.com'
> DBA, Programador, Administrador
>

--
Martín Marqués
select 'martin.marques' || '@' || 'gmail.com'
DBA, Programador, Administrador

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2011-08-26 02:41:45 Re: pg_restore with -j fails (works without -j option)
Previous Message Martín Marqués 2011-08-26 00:46:30 passing cursors from one PL function to another