PostgreSQL has IF/ELSE, CASE, and LOOP and WHILE statements for flow control options. For the IF/ELSE example we used in MySQL, you would need to use a CASE statement in PostgreSQL.
The LOOP statement in PostgreSQL is similar to the REPEAT statement in MySQL and uses the following syntax:
[looplabel]
LOOP
sql statements go here;
EXIT [looplabel] WHEN condition;
END LOOP;
The WHILE statement in PostgreSQL, which is very similar to the WHILE statement in MySQL, uses the following syntax:
[whilelabel]
WHILE condition LOOP
sql statements go here;
END LOOP;
For more information about PostgreSQL flow control, take a look at the Further reading section.