Is it possible to use a for loop in postgresql (Function)
Asked
Active
Viewed 196 times
1
-
2Yes. Read documentaion for more details – Alex Yu Jun 16 '18 at 10:00
-
No. Don't read the documentation – olleo Jun 16 '18 at 13:02
-
Possibly. Hope the documentation finds you – vol7ron Jun 16 '18 at 13:31
1 Answers
0
In a word - yes. The syntax is quite simple and straightforward:
FOR i IN 1..10 LOOP
-- Do something with i
END LOOP;
You can also go backwards (by using the REVERSE
keyword before specifying the range) and control the size of the step by using a BY
clause.
See the documentation for the complete details.

Mureinik
- 297,002
- 52
- 306
- 350