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 <Kevin.Grittner@wicourts.gov>
Cc: Jeff Wu <jwu@atlassian.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #5974: UNION construct type cast gives poor error message
Date: Wed, 13 Apr 2011 19:26:06 -0400
Message-ID: <1308.1302737166@sss.pgh.pa.us> (raw)
In-Reply-To: <4DA5E1B8020000250003C7DC@gw.wicourts.gov>
References: <201104122018.p3CKIlWR042915@wwwmaster.postgresql.org>
	<201104122018.p3CKIlWR042915@wwwmaster.postgresql.org>
	<9799.1302719551@sss.pgh.pa.us>
	<4DA5B8A4020000250003C7A9@gw.wicourts.gov>
	<4DA5B8A4020000250003C7A9@gw.wicourts.gov>
	<11920.1302727156@sss.pgh.pa.us>
	<4DA5CADB020000250003C7BE@gw.wicourts.gov>
	<4DA5CADB020000250003C7BE@gw.wicourts.gov>
	<24771.1302730369@sss.pgh.pa.us>
	<4DA5E1B8020000250003C7DC@gw.wicourts.gov>

"Kevin Grittner" <Kevin.Grittner@wicourts.gov> writes:
> Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> The sticking point is just that in purely syntactic terms this is
>> action-at-a-distance, and so it's hard to square with the spec.  I
>> think that our current reading (in which the '1' and '2' get
>> resolved as text) is actually closer to what the spec says.
 
> Would the approach you have in mind accept a query which is valid
> under the spec yet return different results?  If not, we can
> legitimately call it an extension.

Well, the case that is bothering me is stuff like

	(select '1' union select '1 ') union all select 2;

The first union produces 1 row if you resolve the constants as integers,
but 2 rows if you resolve as text, which I think is what the spec would
expect here.  And since the second union has ALL, that makes a
difference to the final output.  Now in this particular case we'd fail
with "UNION types text and integer cannot be matched" so you never get
as far as noticing what the runtime behavior is.

[ experiments a bit... ]  You can show a difference in results with
this:

regression=# (select '1' union select '1 ') union all select '2'::bpchar;
 ?column? 
----------
 1
 1 
 2
(3 rows)

This produces 3 rows because the UNION resolves as text, but what we're
discussing here would allow it to resolve as bpchar, which would have
different behavior:

regression=# (select '1' union select '1 '::bpchar) union all select '2'::bpchar;
 ?column? 
----------
 1
 2
(2 rows)

It's debatable about how important this is, and one could also say that
the behavior of our bpchar is not entirely standards compliant in the
first place, so maybe this isn't a compelling example.  But I'm worried
that there may be related cases where it's a bigger deal.

			regards, tom lane



view thread (20+ messages)  latest in thread

Message-ID: <1308.1302737166@sss.pgh.pa.us>
Permalink:  ../1308.1302737166@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1308.1302737166@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, Kevin.Grittner@wicourts.gov, jwu@atlassian.com
  Subject: Re: BUG #5974: UNION construct type cast gives poor error message
  In-Reply-To: <1308.1302737166@sss.pgh.pa.us>
  References: <201104122018.p3CKIlWR042915@wwwmaster.postgresql.org> <9799.1302719551@sss.pgh.pa.us> <4DA5B8A4020000250003C7A9@gw.wicourts.gov> <11920.1302727156@sss.pgh.pa.us> <4DA5CADB020000250003C7BE@gw.wicourts.gov> <24771.1302730369@sss.pgh.pa.us> <4DA5E1B8020000250003C7DC@gw.wicourts.gov> <1308.1302737166@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