From: Tom Lane <tgl@sss.pgh.pa.us>
To: 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 14:32:31 -0400
Message-ID: <9799.1302719551@sss.pgh.pa.us> (raw)
In-Reply-To: <201104122018.p3CKIlWR042915@wwwmaster.postgresql.org>
References: <201104122018.p3CKIlWR042915@wwwmaster.postgresql.org>
"Jeff Wu" <jwu@atlassian.com> writes:
> The UNION construct (as noted on this page:
> http://www.postgresql.org/docs/9.0/static/typeconv-union-case.html) will
> cast unknown types to TEXT, however, if you try to do three or more UNIONs
> the order in which the UNIONs are executed will cause some columns to be
> cast to TEXT prematurely. The result is a type mismatch error.
Really the *right* fix for this would be to resolve the common type
just once across the whole nest of set operations. That wouldn't be
terribly difficult from a coding standpoint, I think. The reason we
haven't done it is that it looks like the SQL standard requires type
resolution for set-ops to happen one pair of input relations at a time.
See SQL:2008 7.13 <query expression>, in which everything that's said
about UNION/INTERSECT/EXCEPT is phrased in terms of exactly two input
subqueries; for instance INTERSECT's result type is defined in syntax
rule 18b as:
The declared type of the i-th column of TR is determined by
applying Subclause 9.3, "Result of data type combinations", to
the declared types of the i-th column of T1 and the i-th column
of T2.
If anyone can think of a way to read the spec to allow subclause 9.3 to
be applied to the whole set of columns at once, we could make this work
less surprisingly. Or maybe we could find out that some other products
do it like that despite what the spec says?
regards, tom lane
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, jwu@atlassian.com
Subject: Re: BUG #5974: UNION construct type cast gives poor error message
In-Reply-To: <9799.1302719551@sss.pgh.pa.us>
References: <201104122018.p3CKIlWR042915@wwwmaster.postgresql.org> <9799.1302719551@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