COALESCE doccumentation

PG Doc comments form <[email protected]>
Newsgroups gmane.comp.db.postgresql.devel.documentation
Message-ID <[email protected]>
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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.