Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id D7E811337BEB for ; Thu, 14 Apr 2011 12:24:54 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 67308-04 for ; Thu, 14 Apr 2011 15:24:47 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from milan.hostgo.com (milan.hostgo.com [72.52.99.130]) by mail.postgresql.org (Postfix) with ESMTP id 9272D1337BEF for ; Thu, 14 Apr 2011 12:24:47 -0300 (ADT) Received: from [217.10.134.34] (helo=[192.168.1.71]) by milan.hostgo.com with esmtpa (Exim 4.69) (envelope-from ) id 1QAOPR-0005hj-IC; Thu, 14 Apr 2011 11:24:42 -0400 Message-ID: <4DA711B6.4060306@mlfowler.com> Date: Thu, 14 Apr 2011 16:24:38 +0100 From: Mike Fowler User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101208 Lightning/1.0b2 Thunderbird/3.1.7 MIME-Version: 1.0 To: Tom Lane CC: Jeff Wu , pgsql-bugs@postgresql.org Subject: Re: BUG #5974: UNION construct type cast gives poor error message References: <201104122018.p3CKIlWR042915@wwwmaster.postgresql.org> <9799.1302719551@sss.pgh.pa.us> In-Reply-To: <9799.1302719551@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - milan.hostgo.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - mlfowler.com X-Source: X-Source-Args: X-Source-Dir: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201104/93 X-Sequence-Number: 30012 On 13/04/11 19:32, Tom Lane wrote: > "Jeff Wu" 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. > > > Or maybe we could find out that some other products > do it like that despite what the spec says? > > regards, tom lane I happen to have a MS SQLServer 2008 instance at work as well as a MySQL 5.1 and an Oracle 10g. With the query: SELECT 1,null,null UNION SELECT 2,3,null UNION SELECT 3,null,4 In MS SQLServer I get (NB: no column headings): ---------------------- ---------------------- 1 | | 2 | 3 | 3 | | 4 In MySQL I get: -------------------- 1 | NULL | NULL -------------------- 1 | | 2 | 3 | 3 | | 4 In Oracle I get a delicious error message: Error: ORA-00923: FROM keyword not found where expected SQLState: 42000 ErrorCode: 923 Position: 19 Regards, -- Mike Fowler Registered Linux user: 379787