COALESCE returns the first of multiple arguments that is not NULL.

Syntax


COALESCE ( expression1, expression2 [, expressionN ] )

Arguments

  • expression: At least two expressions for comparison. These expressions must be of types that can be compared to each other.

  • Use CAST or otherwise convert types when required to create the proper argument types.

Returns

The first encountered expression which is not NULL, or NULL if all arguments are NULL.

Examples


VALUES COALESCE (<null>, 3, 4)
-- Returns 3

VALUES COALESCE (4, <null>, 3)
-- Returns 4