cursors

Started by Cesar Alvarezover 18 years ago4 messagesgeneral
Jump to latest
#1Cesar Alvarez
c.alvarezx66@gmail.com

Hello every one.
im trying to make a Loop and i found in the manual this.

FOR <target> IN <query> LOOP
<statements>
END LOOP

Can i use cursor instead of the Query in the loop?? ,
this es more legible than using the open/fetch/close of the cursor.

Regard Cesar Alvarez.

#2Pavel Stehule
pavel.stehule@gmail.com
In reply to: Cesar Alvarez (#1)
Re: cursors

On 24/11/2007, Cesar Alvarez <c.alvarezx66@gmail.com> wrote:

Hello every one.
im trying to make a Loop and i found in the manual this.

FOR <target> IN <query> LOOP
<statements>
END LOOP

Can i use cursor instead of the Query in the loop?? ,
this es more legible than using the open/fetch/close of the cursor.

Regard Cesar Alvarez.

Hello

FOR statement use cursor internally. If you wont to use cursor
explicitly, you have to use WHILE loop.

Regards
Pavel Stehule

Show quoted text

---------------------------(end of
broadcast)---------------------------
TIP 6: explain analyze is your friend

#3Cesar Alvarez
c.alvarezx66@gmail.com
In reply to: Pavel Stehule (#2)
Re: cursors

Thanks,
what will be the syntax for that type of for?

Pavel Stehule wrote:

Show quoted text

On 24/11/2007, Cesar Alvarez <c.alvarezx66@gmail.com> wrote:

Hello every one.
im trying to make a Loop and i found in the manual this.

FOR <target> IN <query> LOOP
<statements>
END LOOP

Can i use cursor instead of the Query in the loop?? ,
this es more legible than using the open/fetch/close of the cursor.

Regard Cesar Alvarez.

Hello

FOR statement use cursor internally. If you wont to use cursor
explicitly, you have to use WHILE loop.

Regards
Pavel Stehule

---------------------------(end of
broadcast)---------------------------
TIP 6: explain analyze is your friend

#4Pavel Stehule
pavel.stehule@gmail.com
In reply to: Cesar Alvarez (#3)
Re: cursors

On 24/11/2007, Cesar Alvarez <c.alvarezx66@gmail.com> wrote:

Thanks,
what will be the syntax for that type of for?

DECLARE
curs2 CURSOR FOR SELECT * FROM tenk1;
c1 integer;
c2 integer;
BEGIN
OPEN curs2;
FETCH curs2 INTO c1,c2;
WHILE found LOOP
...
FETCH curs2 INTO c1,c2;
END LOOP;
CLOSE curs2;

http://www.postgresql.org/docs/8.2/interactive/plpgsql-control-structures.html#PLPGSQL-CONTROL-STRUCTURES-LOOPS

Regards
Pavel Stehule

Show quoted text

Pavel Stehule wrote:
On 24/11/2007, Cesar Alvarez <c.alvarezx66@gmail.com> wrote:

Hello every one.
im trying to make a Loop and i found in the manual this.

FOR <target> IN <query> LOOP
<statements>
END LOOP

Can i use cursor instead of the Query in the loop?? ,
this es more legible than using the open/fetch/close of the cursor.

Regard Cesar Alvarez.

Hello

FOR statement use cursor internally. If you wont to use cursor
explicitly, you have to use WHILE loop.

Regards
Pavel Stehule

---------------------------(end of
broadcast)---------------------------
TIP 6: explain analyze is your friend