COALESCE documentation

From: Navrátil, Ondřej <onavratil(at)monetplus(dot)cz>
To: pgsql-docs(at)lists(dot)postgresql(dot)org
Subject: COALESCE documentation
Date: 2024-07-02 10:45:16
Message-ID: CAEELDaqnn5GayihUUhnKLR1_fegb-_b2i+4_dP4U192uK7j9vw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

Hello,

as per documentation
<https://www.postgresql.org/docs/current/functions-conditional.html#FUNCTIONS-COALESCE-NVL-IFNULL>
> The COALESCE function returns the first of its arguments that is not
null. Null is returned only if all arguments are null.

This is not exactly true. In fact:
The COALESCE function returns the first of its arguments that *is
distinct* *from
*null. Null is returned only if all arguments *are not distinct from* null.

See my stack overflow question here
<https://stackoverflow.com/questions/78691097/postgres-null-on-composite-types>
.

Long story short

select coalesce((null, null), (10, 20)) as magic;

returns

magic -------
(,)
(1 row)

However, this is true:

select (null, null) is null;

--

*Ing. Ondřej Navrátil, Ph.D.*
IT Analytik
M +420 728 625 950
E onavratil(at)monetplus <onavratil(at)monetplus(dot)cz>.cz <onavratil(at)monetplus(dot)cz>

MONET+,a.s., Za Dvorem 505, 763 14 Zlín-Štípa
monetplus.com <https://www.monetplus.cz/> | linkedin
<https://www.linkedin.com/company/monetplus/> | facebo
<https://www.facebook.com/monetplus/>ok
<https://www.facebook.com/monetplus/>

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message PG Doc comments form 2024-07-02 20:00:26 tutorial not accurate
Previous Message David G. Johnston 2024-06-28 21:01:33 Re: Missing information on '-X' in section 26.3.6.1.