pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Kevin Grittner <kgrittn@ymail.com>
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, 03 May 2015 13:13:51 -0400
Message-ID: <16778.1430673231@sss.pgh.pa.us> (raw)
In-Reply-To: <1439794807.1364461.1430410005618.JavaMail.yahoo@mail.yahoo.com>
References: <35651.1430347071@sss.pgh.pa.us>
	<1439794807.1364461.1430410005618.JavaMail.yahoo@mail.yahoo.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

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, for essentially the reason SQL Server
gives:

> At least one of the arguments to COALESCE must be an expression that is not the NULL constant.

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.  Our choice to resolve it as text rather than
failing is admittedly a bit arbitrary, but I don't find it unreasonable.

> Here the other:

> test=# select null as ts union all select null union all select now();
> ERROR:  UNION types text and timestamp with time zone cannot be matched

Yeah, this one is a bit annoying, especially considering we do get it
right in related cases:

regression=# select null as ts union all (select null union all select now());
              ts               
-------------------------------
 
 
 2015-05-03 13:05:30.639594-04
(3 rows)

It's possible this could be fixed with some rejiggering of parse analysis
so that matching of output-column types is performed across a whole
set-operation tree at once rather than on binary pairs of leaf queries.

On the other hand, a case could be made that such behavior would also be
in violation of the standard, which is perfectly clear that you process
set operations as binary pairs not holistically.  There would certainly
be some compatibility risk involved in changing the resolution behavior
like that, especially for cases where the type choice affects the set
operation's behavior significantly.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (42+ messages)  latest in thread

Message-ID: <16778.1430673231@sss.pgh.pa.us>
Permalink:  ../16778.1430673231@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/16778.1430673231@sss.pgh.pa.us

 · 

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 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: tgl@sss.pgh.pa.us, kgrittn@ymail.com, robertmhaas@gmail.com, pgsql@j-davis.com
  Subject: Re: Failure to coerce unknown type to specific type
  In-Reply-To: <16778.1430673231@sss.pgh.pa.us>
  References: <35651.1430347071@sss.pgh.pa.us> <1439794807.1364461.1430410005618.JavaMail.yahoo@mail.yahoo.com> <16778.1430673231@sss.pgh.pa.us>

* 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