1

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

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
  • 297,002
  • 52
  • 306
  • 350