1

Is it possible to use a for loop in postgresql (Function)

a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843

1 Answers1

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
  • 277,661
  • 50
  • 283
  • 320