pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Doc comments form <noreply@postgresql.org>
To: pgsql-docs@lists.postgresql.org
Cc: t.dnil@yahoo.com
Subject: COALESCE doccumentation
Date: Sat, 27 Apr 2019 20:26:57 +0000
Message-ID: <155639681797.1368.1856073093791885251@wrigleys.postgresql.org> (raw)

The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/11/functions-conditional.html
Description:

The documentation says:

"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"

Which is NOT TRUE. In addition, it is obscure and misleading.

The COALESCE(<value expression>, ..., <value expression>) scans the list of
<value expression>s from left to right, determines the highest data type in
the list and returns the first non-NULL in the list, casting it to the
highest data type selected in the previous step, but if all the <value
expressions>s are NULL, the result is NULL. In case when any of the <value
expressions>s in the list cannot be evaluated to the highest data type then
exception is thrown.

Try, for example. 

SELECT COALESCE(NULL, '12', 3, 1, 1); -- OK!
SELECT COALESCE(NULL, '12.2', 3.2, '1', 1.1); -- OK!
SELECT COALESCE(NULL, '1d2', 3, 1, 1); -- error
SELECT COALESCE(NULL, '12', 3, '1d', 1); -- cast error

Thanks.


view thread (7+ messages)  latest in thread

Message-ID: <155639681797.1368.1856073093791885251@wrigleys.postgresql.org>
Permalink:  ../155639681797.1368.1856073093791885251@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/155639681797.1368.1856073093791885251@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-docs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-docs@lists.postgresql.org, t.dnil@yahoo.com
  Subject: Re: COALESCE doccumentation
  In-Reply-To: <155639681797.1368.1856073093791885251@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox