postgresql

COALESCE

Introduction#

Coalesce returns the first none null argument from a set of arguments. Only the first non null argument is return, all subsequent arguments are ignored. The function will evaluate to null if all arguments are null.

Single non null argument

PGSQL> SELECT COALESCE(NULL, NULL, 'HELLO WORLD');

coalesce
--------
'HELLO WORLD'

Multiple non null arguments

PGSQL> SELECT COALESCE(NULL, NULL, ‘first non null’, null, null, ‘second non null’);

coalesce
--------
'first non null'

All null arguments

PGSQL> SELECT COALESCE(NULL, NULL, NULL);

coalesce
--------

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow