From: Kevin Grittner <kgrittn@ymail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Jeff Davis <pgsql@j-davis.com>
Cc: Postgres-Bugs <pgsql-bugs@postgresql.org>
Subject: Re: Failure to coerce unknown type to specific type
Date: Sun, 3 May 2015 18:56:14 +0000 (UTC)
Message-ID: <1850649255.594603.1430679374313.JavaMail.yahoo@mail.yahoo.com> (raw)
In-Reply-To: <16778.1430673231@sss.pgh.pa.us>
References: <16778.1430673231@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Kevin Grittner <kgrittn@ymail.com> writes:
>> I recall two constructs that we had in production that caused some
>> pain moving to PostgreSQL.
>
>> Here's one:
>
>> test=# insert into x values (coalesce(null, null));
>> ERROR: column "d" is of type date but expression is of type text
>
> I don't have a lot of sympathy for that one. coalesce(null, null)
> isn't legal at all per SQL spec
I don't get that from my reading of the SQL spec. A COALESCE
clause is (and always has been) considered a short form of the CASE
clause (not to be mistaken for a function, for example). The spec
section 6.11 1) c) very explicitly requires
COALESCE(NULL, NULL)
be the exact equivalent of
CASE WHEN NULL IS NOT NULL THEN NULL ELSE NULL END
Yet in PostgreSQL the long form of the CASE clause returns the same
thing as a bare NULL, while the short form (COALESCE) gives an
error. Please indicate what in the spec makes you think that
COALESCE(NULL, NULL) should ever be treated differently from a bare
NULL, because I've looked at the spec and I'm not seeing anything
to support what you said.
> Otherwise the result type of coalesce() isn't well-defined, and there is
> nothing at all in the spec that would suggest looking to surrounding
> context to decide that.
The definition of COALESCE says that when there are different types
the result type should be determined according to section 9.3
(Result of data type combinations). Because the organization of
our code doesn't lend itself well to conforming to the standard in
that regard, I realize that we are dealing in practical
compromises; but let's not pretend the spec is not clear about
this.
--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: kgrittn@ymail.com, tgl@sss.pgh.pa.us, robertmhaas@gmail.com, pgsql@j-davis.com
Subject: Re: Failure to coerce unknown type to specific type
In-Reply-To: <1850649255.594603.1430679374313.JavaMail.yahoo@mail.yahoo.com>
References: <16778.1430673231@sss.pgh.pa.us> <1850649255.594603.1430679374313.JavaMail.yahoo@mail.yahoo.com>
* 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