RE: Cursores

From: Conrado Blasetti <conrado(at)mapfre(dot)com(dot)ar>
To: pgsql-es-ayuda(at)postgresql(dot)org
Cc: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Subject: RE: Cursores
Date: 2005-10-26 18:57:18
Message-ID: 65746BCC3D99E44998976FD845AD6E6E0DF7DF7F@MAIL
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Es correcto Alvaro, en ningun lado lo dice y por eso no funcionaba
(costumbres de otro lenguaje...)
Por otro lado, comento que fue resulto asi:

declare
reg cursor ( p_id int8 ) is
select * from tabla
where id = p_id;

c1 tabla%type;

begin
open reg ( 99 );
fetch reg into c1;
while FOUND loop
...
...
...
...
fetch reg into c1;
end loop;
close reg;
end;

Mas que costumbre de otro lenguaje, apuntaba a tener el SELECT en el DECLARE
(en la definicion de cada cursor) y no dentro de BEGIN (llamese comodidad si
se quiere).
Igualmente, gracias.
Saludos,

-----Mensaje original-----
De: Alvaro Herrera [mailto:alvherre(at)alvh(dot)no-ip(dot)org]
Enviado el: Miércoles, 26 de Octubre de 2005 03:23 p.m.
Para: Conrado Blasetti
CC: pgsql-es-ayuda(at)postgresql(dot)org
Asunto: Re: [pgsql-es-ayuda] Cursores

Conrado Blasetti escribió:
> Alvaro, gracias por responder.
> En la documentación figura tal cual me sugeris el abrir el cursor, y hacer
> el fetch entre otras cosas.
> El fetch me funciona sin problema.
> El inconveniente viene con el for loop, haciendo el open (antes del for) y
> el close (luego del end loop) tampoco funciona.

Vaya, yo pense que podia funcionar pero evidentemente no es asi.
Simplemente olvidate del cursor y declara el SELECT en el loop. Si te
fijas en la documentacion de LOOP, en ninguna parte dice que puedas usar
el cursor ahi. Tienes que especificar el SELECT directamente.

--
Alvaro Herrera Developer,
http://www.PostgreSQL.org
You liked Linux a lot when he was just the gawky kid from down the block
mowing your lawn or shoveling the snow. But now that he wants to date
your daughter, you're not so sure he measures up. (Larry Greenemeier)

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Milton inostroza 2005-10-26 19:04:46 transformar funciones y procedimientos almacenados desde M$SQLServer a PostgreSQL
Previous Message Alvaro Herrera 2005-10-26 18:22:42 Re: Cursores