October 2001
Beginner to intermediate
400 pages
7h 45m
English
PostgreSQL includes several functions that return values based on expressions supplied in the current SQL statement. Moreover, these functions are not constrained to acting on specific data types; rather, they act as control structures within a SQL statement.
The CASE WHEN function is a simple conditional evaluation tool. Most programming languages contain similar constructs. It can be thought of as analogous to the ubiquitous IF…THEN…ELSE statement.
CASE WHEN condition THEN result
[ WHEN condition THEN result ]
…
[ ELSE result ]
END This example shows a classic IF…THEN…ELSE paradigm in which the CASE WHEN function can be used. The age of an employee is compared against certain constants, ...
Read now
Unlock full access