| The PostgreSQL 9.0 Reference Manual - Volume 2 - Programming Guide
by The PostgreSQL Global Development Group Paperback (6"x9"), 478 pages ISBN 9781906966065 RRP £14.95 ($19.95) Sales of this book support the PostgreSQL project! Get a printed copy>>> |
9.6.2.4 Simple CASE
CASE search-expression
WHEN expression [, expression [ ... ]] THEN
statements
[ WHEN expression [, expression [ ... ]] THEN
statements
... ]
[ ELSE
statements ]
END CASE;
The simple form of CASE provides conditional execution
based on equality of operands. The search-expression
is evaluated (once) and successively compared to each
expression in the WHEN clauses.
If a match is found, then the corresponding
statements are executed, and then control
passes to the next statement after END CASE. (Subsequent
WHEN expressions are not evaluated.) If no match is
found, the ELSE statements are
executed; but if ELSE is not present, then a
CASE_NOT_FOUND exception is raised.
Here is a simple example:
CASE x
WHEN 1, 2 THEN
msg := 'one or two';
ELSE
msg := 'other value than one or two';
END CASE;
| ISBN 9781906966065 | The PostgreSQL 9.0 Reference Manual - Volume 2 - Programming Guide | See the print edition |