Skip site navigation (1) Skip section navigation (2)

Re: FOR-IN-EXECUTE: FOR does not replanned on each entry to the FOR loop

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Eugen(dot)Konkov(at)aldec(dot)com
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: FOR-IN-EXECUTE: FOR does not replanned on each entry to the FOR loop
Date: 2008-03-28 14:58:05
Message-ID: 3743.1206716285@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-bugs
<Eugen(dot)Konkov(at)aldec(dot)com> writes:
> --WHILE (v_parent_ID IS NOT NULL) LOOP
> -- EXECUTE 'SELECT parent_ID, name FROM akh_build WHERE ID = ' || 
> quote_literal(v_parent_ID) INTO v_row;
> -- return next v_row;
> -- v_parent_ID= v_row.parent_ID;
> --END LOOP;

> FOR v_row IN EXECUTE 'SELECT parent_ID, name FROM akh_build WHERE ID = ' || 
> quote_literal(v_parent_ID) LOOP
>  return next v_row;
>  v_parent_ID= v_row.parent_ID;
> END LOOP;

> FOR and WHILE results differ

Well, sure.  They are supposed to.

> While docs says:
> 38.6.4. Looping Through Query Results
> ....
> This is like the previous form, except that the source query is specified as 
> a string expression, which is evaluated and replanned on each entry to the 
> FOR loop 

It is evaluated when starting the loop, not each time around the body
of the loop.  I can hardly even imagine what the semantics you suggest
would be like.

			regards, tom lane

In response to

pgsql-bugs by date

Next:From: Heikki LinnakangasDate: 2008-03-28 15:01:33
Subject: Re: [PATCHES] Incomplete docs for restore_command for hotstandby
Previous:From: Tom LaneDate: 2008-03-28 14:55:30
Subject: Re: Redundant explicit field name/types description while select from function with return type of record

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group