Is it possible to use a for loop in postgresql (Function)
-
2Yes. Read documentaion for more detailsAlex Yu– Alex Yu2018-06-16 10:00:36 +00:00Commented Jun 16, 2018 at 10:00
-
No. Don't read the documentationolleo– olleo2018-06-16 13:02:52 +00:00Commented Jun 16, 2018 at 13:02
-
Possibly. Hope the documentation finds youvol7ron– vol7ron2018-06-16 13:31:27 +00:00Commented Jun 16, 2018 at 13:31
Add a comment
|
1 Answer
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.