Selects the first non null operand

Syntax

COALESCE(…expr1…, …expr2…, …)

…expr1… |? …expr2…

Typing

(t?, t?, …, t?) -> t?

(t?, t?, …, t) -> t

Description

Accept a list of alternative values of the same type and returns the first one that is not NULL.

All alternatives but the last must be nullable.

If all alternatives are NULL then returns NULL.

Examples

expression evaluates to
NULL |? 1 1
COALESCE(IF RANDOM > 1 THEN "can't happen", "ok") "ok"

See Also

Convert to not-null or crash Check for NULL