Re: How to quote the COALESCE function? - Mailing list pgsql-general

From Kevin Grittner
Subject Re: How to quote the COALESCE function?
Date
Msg-id CACjxUsMJCHcYjEcg+sQ+HoidEWFgi4LTumMUsDiaSxOZ=AVM-Q@mail.gmail.com
Whole thread Raw
In response to Re: How to quote the COALESCE function?  (Pavel Stehule <pavel.stehule@gmail.com>)
List pgsql-general
On Tue, Mar 29, 2016 at 12:38 PM, Pavel Stehule <pavel.stehule@gmail.com> wrote:

> The coalesce is one few functions implemented by special rule in
> PostgreSQL parser.

In the SQL standard the COALESCE feature is not listed as a
function; it is listed as one of the short forms of CASE
expression.  While it has function-like syntax, thinking of it as a
function is semantically incorrect.

  COALESCE(a, b)

is supposed to be semantically equivalent to:

  CASE WHEN a is not null THEN a ELSE b END

Among other things, that means that this statement should not
generate a divide by zero error:

  SELECT COALESCE(1, 1/0);

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


pgsql-general by date:

Previous
From: Rodney Lott
Date:
Subject: Re: postgresql 9.3.10, FIPS mode and DRBG issues.
Next
From: Soni M
Date:
Subject: Re: CORRUPTION on TOAST table