pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
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 21:15:27 +0000 (UTC)
Message-ID: <946937656.655853.1430687727733.JavaMail.yahoo@mail.yahoo.com> (raw)
In-Reply-To: <25218.1430684934@sss.pgh.pa.us>
References: <25218.1430684934@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:

>> If we
>> *are* going to allow it, it would be pretty confusing to have it
>> behave differently that what I previously outlined (regarding the
>> equivalent long form CASE clause).
>
> AFAICT, we do treat them the same; can you provide an example where
> we don't?

No, I was just arguing that if we change the CASE clause to return 
untyped NULL, then the COALESCE clause should follow suit.

> It would be interesting to try variants of the
>
>     select u+i from (select '1' as u, '2'::int as i) s where u<'foo'::text;
>
> example to see what they do if the column has to be converted to two
> mutually inconsistent types, assuming you can find candidate types
> in each system.

I finagled a syntax that was accepted by all servers on SQL Fiddle 
and got a row with a 3 without the WHERE clause from all products 
except PostgreSQL:

-- Build Schema
create table onerow (n int not null);
insert into onerow values (1);
-- Run SQL
select u+i from (select cast('1' as char) as u, 2 as i from onerow) s;

Then I added that WHERE clause.

select u+i from (select cast('1' as char) as u, 2 as i from onerow) s
where u<cast('foo' as char);


Much to my amazement, all of them *still* return a row with the
value 3, without error.  I'm still picking my jaw up from the floor.

I'm OK with being in the minority on that!

> Another idea would be to try things like
>
>     select u+i from (select 'bar' as u, '2'::int as i) s where u<'foo'::text;
>
> and see exactly what error gets thrown.

I changed '1' to 'bar' in the above code.

MySQL and SQL Lite return a row with a 2.

Oracle throws an error: ORA-01722: invalid number 

MS SQL Server throws an error: Conversion failed when converting the varchar value 'bar ' to data type int.


Yes, my literal was three characters and the error message added a space.


>> To restate it, this hardly seems like the most important issue to
>> address; I just don't think the standard gives us much cover here.
>
> I stand by my opinion that the cases that are controversial here
> are all illegal per spec.

With that last bit you pointed out, I now agree.

> We may well want to allow them on usability
> grounds, but what the spec does *not* provide any cover for is claiming
> that the spec requires some particular non-error interpretation.

ok

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



view thread (42+ messages)

Message-ID: <946937656.655853.1430687727733.JavaMail.yahoo@mail.yahoo.com>
Permalink:  ../946937656.655853.1430687727733.JavaMail.yahoo@mail.yahoo.com/
Also on:    postgresql.org/message-id/946937656.655853.1430687727733.JavaMail.yahoo@mail.yahoo.com

 · 

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: 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: <946937656.655853.1430687727733.JavaMail.yahoo@mail.yahoo.com>
  References: <25218.1430684934@sss.pgh.pa.us> <946937656.655853.1430687727733.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