Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id C58181337BD3 for ; Tue, 12 Apr 2011 17:18:48 -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 39696-02 for ; Tue, 12 Apr 2011 20:18:48 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by mail.postgresql.org (Postfix) with ESMTP id C4B1C1337B3E for ; Tue, 12 Apr 2011 17:18:47 -0300 (ADT) Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by wwwmaster.postgresql.org (8.14.3/8.14.3) with ESMTP id p3CKIl5s042916 for ; Tue, 12 Apr 2011 20:18:47 GMT (envelope-from www@wwwmaster.postgresql.org) Received: (from www@localhost) by wwwmaster.postgresql.org (8.14.3/8.14.3/Submit) id p3CKIlWR042915; Tue, 12 Apr 2011 20:18:47 GMT (envelope-from www) Date: Tue, 12 Apr 2011 20:18:47 GMT Message-Id: <201104122018.p3CKIlWR042915@wwwmaster.postgresql.org> To: pgsql-bugs@postgresql.org Subject: BUG #5974: UNION construct type cast gives poor error message From: "Jeff Wu" Content-Type: text/plain; charset=utf-8 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 201104/66 X-Sequence-Number: 29985 The following bug has been logged online: Bug reference: 5974 Logged by: Jeff Wu Email address: jwu@atlassian.com PostgreSQL version: 9.0 Operating system: Mac OS X Description: UNION construct type cast gives poor error message Details: 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. For example: SELECT 1,null,null UNION SELECT 2,3,null UNION SELECT 3,null,4 will fail while SELECT 1,null,null::INTEGER UNION SELECT 2,3,null UNION SELECT 3,null,4 will succeed. This is not a critical error, but I would say that the error message is misleading because it is not obvious that Postgres casts unknown columns to TEXT automatically. The current error message is: ERROR: UNION types text and integer cannot be matched I would suggest something like: ERROR: UNION types text and integer cannot be matched. HINT: Postgres casts unknown types to TEXT by default. Thanks, Jeff