Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 2220B1337B68 for ; Wed, 13 Apr 2011 20:42:08 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 86905-10 for ; Wed, 13 Apr 2011 23:42:01 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 9C78E133798E for ; Wed, 13 Apr 2011 20:41:59 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p3DNftu7001517; Wed, 13 Apr 2011 19:41:55 -0400 (EDT) To: "Kevin Grittner" cc: "Jeff Wu" , pgsql-bugs@postgresql.org Subject: Re: BUG #5974: UNION construct type cast gives poor error message In-reply-to: <4DA5E54F020000250003C7E8@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> <4DA5E54F020000250003C7E8@gw.wicourts.gov> Comments: In-reply-to "Kevin Grittner" message dated "Wed, 13 Apr 2011 18:02:55 -0500" Date: Wed, 13 Apr 2011 19:41:55 -0400 Message-ID: <1516.1302738115@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201104/90 X-Sequence-Number: 30009 "Kevin Grittner" writes: > I'm not sure the spec requires *any* of them to work. It doesn't. NULL in the standard is not part of the generic expression syntax; it only appears as (which lets it be the direct argument of CAST, or the DEFAULT value for a table column) and as (which lets it be an INSERT or UPDATE's direct source value). So far as I can see, these are the only contexts where a NULL literal is allowed in SQL99. The syntax rule for a NULL literal is interesting too: 2) The declared type DT of a NS is determined by the context in which NS appears. NS is effectively replaced by CAST ( NS AS DT ). NOTE 70 - In every such context, NS is uniquely associated with some expression or site of declared type DT, which thereby becomes the declared type of NS. The NOTE makes it pretty clear that this is intentional and not some sort of omission. I have not tried to trace the syntax productions to verify that this is still true in SQL:2008 (mainly because I don't have an easily greppable copy of that standard) but I see that the above text is still there in 6.5 . In short: the standard disallows an un-cast NULL in a SELECT's targetlist a priori, let alone one in a SELECT that's an arm of a set operation. I doubt we want to copy that ... regards, tom lane