Coalesce function in Redshift database

In Redshift database, COALESCE is the alias for NVL function. Both NVL and COALESCE return the same output.

NVL returns the first non-null value in the list of expressions passed to the function.

Syntax:

SELECT NVL(value1, value2, value3, ..) from table1;

SELECT COALESCE(value1, value2, value3, ..) from table1;

Returns value1 if value1 is not null

Returns value2 if value1 is null

Returns value3 if both value1 and value2 are null.

COALESCE function is very useful to return a non-null value if the value you’re looking for is null.

See also  How to enable and disable programmatic access to an IAM user