Conditional statements are usually part of flow control statements, which include also iterations.
While iterating is not directly supported by psql, a similar effect can be achieved in other ways. For instance:
- A script, called for instance file.sql, can be iterated by adding some lines at the end, as in the following fragment:
SELECT /* add a termination condition as appropriate */ AS do_loop
\gset
\if do_loop
\ir file.sql
\endif
- Instead of iterating, you can follow the approach described later in this chapter in the recipe Performing actions on many tables.