IF THEN ELSE
Tests a condition, and if it evaluates to TRUE
performs the statement or block following THEN; otherwise, it
performs the statement or block following ELSE, if present.
<psql_condition> THEN <psql_statement>
ELSE <psql_statement> ]
A PSQL condition. See the section on Conditions for more information.
A PSQL statement. Often this will be a compound statement.
The condition is evaluated and if it evaluates to
TRUE the statement in the THEN clause is executed. If it is not TRUE,
i.e. It evaluates to FALSE or to NULL, and an ELSE clause is present,
then the statement in the ELSE clause is executed.
IF statements can be nested, i.e. The statements
in the THEN or ELSE clauses can be IF statements also. If the THEN
clause contains a IF THEN ELSE statement, then that ELSE clause is
deemed to be part of the nested IF, just as in nearly all other
programming languages. Enclose the nested if in a compound statement
if you want the ELSE clause to refer to the enclosing IF statement.
The below examples show valid uses of the IF
IF (a>23) THEN a = a
IF (myname='Paul') THEN a = a + 1;
ELSE a = i;
WHEN DO statement