Re: existen stored procedures?

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: "bajopalabra(dot)ar" <bajopalabra(dot)ar(at)gmail(dot)com>
Cc: pgsql-es-ayuda(at)postgresql(dot)org
Subject: Re: existen stored procedures?
Date: 2008-10-17 15:01:36
Message-ID: 20081017150136.GG4218@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

bajopalabra.ar escribió:

> el tema de la devolución de varios lotes
> de última, lo puedo llegar a manejar en otra capa

Puedes retornar SETOF refcursor en una función, y de cada cursor obtener un
resultado diferente. Prueba algo así:

alvherre=# create or replace function refcursors () returns setof refcursor
language plpgsql as $$
declare
cursor1 refcursor;
cursor2 refcursor;
begin
open cursor1 for values (1), (2), (3);
return next cursor1;
open cursor2 for values ('foo'), ('bar'), ('baz');
return next cursor2;
end;
$$
;
CREATE FUNCTION
alvherre=# begin;
BEGIN
alvherre=# select * from refcursors();
refcursors
--------------------
<unnamed portal 3>
<unnamed portal 4>
(2 filas)

alvherre=# fetch all from "<unnamed portal 3>";
column1
---------
1
2
3
(3 filas)

alvherre=# fetch all from "<unnamed portal 4>";
column1
---------
foo
bar
baz
(3 filas)

alvherre=# commit;
COMMIT

--
Alvaro Herrera http://www.amazon.com/gp/registry/CTMLCN8V17R4
"In a specialized industrial society, it would be a disaster
to have kids running around loose." (Paul Graham)

In response to

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message keyser soze 2008-10-17 15:08:38 Re: existen stored procedures?
Previous Message Alvaro Herrera 2008-10-17 14:52:55 Re: Consulta Eficiente