RefLib

Reference library for AI

Back

postgresql_16:3.6.18.2 COALESCE

PostgreSQL 16 > The SQL Language > Functions and Operators > Conditional Expressions > COALESCE

COALESCE(value , ...)

The COALESCE function returns the first of its arguments that is not null. Null is returned only if all arguments are null. It is often used to substitute a default value for null values when data is retrieved for display, for example: SELECT COALESCE(description, short_description, '(none)') ... This returns description if it is not null, otherwise short_description if it is not null, otherwise (none).

The arguments must all be convertible to a common data type, which will be the type of the result (see (see postgresql_16:3.7.5) for details).

Like a CASE expression, COALESCE only evaluates the arguments that are needed to determine the result; that is, arguments to the right of the first non-null argument are not evaluated. This SQL-standard function provides capabilities similar to NVL and IFNULL, which are used in some other database systems.

Back