I couldn’t find this immediately from the examples. I want to increment a variable in a loop, in a function.
For instance:
DECLARE
iterator float4;
BEGIN
iterator = 1;
while iterator < 999
.....
iterator ++;
END;
How would this be done?
I was looking at this document about flow control:
http://www.postgresql.org/docs/8.4/static/plpgsql-control-structures.html
And none of them seem to be relevant for me, unless these are absolutely the only ways to simulate incrementing a variable.
To increment a variable in plpgsql:
There is no
++operator.About the assignment operator in plpgsql:
Correct syntax for loops in PL/pgSQL in the manual.
Your code fragment would work like this:
Simpler, faster alternative with a
FORloop:The manual: