- publishing free software manuals
PostgreSQL Reference Manual - Volume 2 - Programming Guide
by The PostgreSQL Global Development Group
Paperback (6"x9"), 408 pages
ISBN 0954612035
RRP £19.95 ($34.95)

Sales of this book support the PostgreSQL project! Get a printed copy>>> IF-THEN-ELSE IF

IF statements can be nested, as in the following example:

IF demo_row.sex = 'm' THEN
    pretty_sex := 'man';
    IF demo_row.sex = 'f' THEN
        pretty_sex := 'woman';
    END IF;

When you use this form, you are actually nesting an IF statement inside the ELSE part of an outer IF statement. Thus you need one END IF statement for each nested IF and one for the parent IF-ELSE. This is workable but grows tedious when there are many alternatives to be checked. Hence the next form.

ISBN 0954612035PostgreSQL Reference Manual - Volume 2 - Programming GuideSee the print edition