coalesce Function |
The coalesce function returns the first (left-most) non-null element from a given set.
ret_val = coalesce(value_set);
ret_val | The first (left-most) non-null element in value_set |
value_set | A set of values to test |
The following example demonstrates the use of the coalesce function to select the most-specific known locale for a street (where the street is identified by id) using the lookup function (which returns null if a match is not made):
$my_region = coalesce(lookup(my_suburbs, %id), lookup(my_cities, %id), "Unknown"));
The above line of code is functionally equivalent to the following:
IF lookup(my_suburbs, %id) != NULL $my_region = lookup(my_suburbs, %id); ELSE IF lookup(my_cities, %id) != NULL $my_region = lookup(my_cities, %id); ELSE $my_region = "Unknown";