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:41:55 -0400
Message-ID: <1516.1302738115@sss.pgh.pa.us> (raw)
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>

"Kevin Grittner" <Kevin.Grittner@wicourts.gov> 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 <implicitly typed value specification> (which
lets it be the direct argument of CAST, or the DEFAULT value for a table
column) and as <contextually typed value specification> (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 <null specification> 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 <contextually typed value specification>.

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



view thread (20+ messages)  latest in thread

Message-ID: <1516.1302738115@sss.pgh.pa.us>
Permalink:  ../1516.1302738115@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1516.1302738115@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: <1516.1302738115@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> <4DA5E54F020000250003C7E8@gw.wicourts.gov> <1516.1302738115@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