|The PostgreSQL 9.0 Reference Manual - Volume 2 - Programming Guide
by The PostgreSQL Global Development Group
Paperback (6"x9"), 478 pages
RRP £14.95 ($19.95)
Sales of this book support the PostgreSQL project! Get a printed copy>>>
126.96.36.199 FOR (integer variant)
[ <<label>> ] FOR name IN [ REVERSE ] expression .. expression [ BY expression ] LOOP statements END LOOP [ label ];
This form of
FOR creates a loop that iterates over a range
of integer values. The variable
name is automatically defined as type
integer and exists only inside the loop (any existing
definition of the variable name is ignored within the loop).
The two expressions giving
the lower and upper bound of the range are evaluated once when entering
the loop. If the
BY clause isn't specified the iteration
step is 1, otherwise it's the value specified in the
clause, which again is evaluated once on loop entry.
REVERSE is specified then the step value is
subtracted, rather than added, after each iteration.
Some examples of integer
FOR i IN 1..10 LOOP -- i will take on the values 1,2,3,4,5,6,7,8,9,10 within the loop END LOOP; FOR i IN REVERSE 10..1 LOOP -- i will take on the values 10,9,8,7,6,5,4,3,2,1 within the loop END LOOP; FOR i IN REVERSE 10..1 BY 2 LOOP -- i will take on the values 10,8,6,4,2 within the loop END LOOP;
If the lower bound is greater than the upper bound (or less than,
REVERSE case), the loop body is not
executed at all. No error is raised.
If a label is attached to the
FOR loop then the integer loop variable can be
referenced with a qualified name, using that
|ISBN 9781906966065||The PostgreSQL 9.0 Reference Manual - Volume 2 - Programming Guide||See the print edition|