pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Richard Huxton <dev@archonet.com>
Cc: ilejn@yandex.ru
Cc: pgsql-general@postgresql.org
Subject: Re: Old question - failed to find conversion function from
Date: Tue, 19 Jul 2005 11:19:06 -0400
Message-ID: <24675.1121786346@sss.pgh.pa.us> (raw)
In-Reply-To: <42DD0BB4.6050108@archonet.com>
References: <42DCC1E9.2060300@aeccom.com>
	<42DCCCCE.000006.04382@mfront8.yandex.ru>
	<42DCDE07.4020906@archonet.com>
	<42DCEFEE.000005.12199@mfront8.yandex.ru>
	<42DD0BB4.6050108@archonet.com>

Richard Huxton <dev@archonet.com> writes:
> [* Actually, I think NULLs are typed in SQL, which means you should be 
> able to get type violations. ]

I'm pretty sure the entire construct is illegal per a strict reading of
the SQL spec --- the spec only allows NULL to appear in contexts where a
datatype can be assigned to it immediately.  Per spec you'd have to
write this as
	select 1 where 5 in (select cast(null as integer));

In the spec, NULL is not a general <expression>, it's a <contextually
typed value expression>, and those are only allowed as the immediate
argument of a CAST(), the immediate column value of an INSERT or UPDATE,
and one or two other very circumscribed cases.  SQL99 section 6.4 is
very clear about what they intend:

         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.

PG's ability to infer a type for a NULL constant goes well beyond what
the spec allows --- but it does have limits.

			regards, tom lane



view thread (8+ messages)  latest in thread

Message-ID: <24675.1121786346@sss.pgh.pa.us>
Permalink:  ../24675.1121786346@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/24675.1121786346@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-admin@postgresql.org
  Cc: tgl@sss.pgh.pa.us, dev@archonet.com, ilejn@yandex.ru, pgsql-general@postgresql.org
  Subject: Re: Old question - failed to find conversion function from
  In-Reply-To: <24675.1121786346@sss.pgh.pa.us>
  References: <42DCC1E9.2060300@aeccom.com> <42DCCCCE.000006.04382@mfront8.yandex.ru> <42DCDE07.4020906@archonet.com> <42DCEFEE.000005.12199@mfront8.yandex.ru> <42DD0BB4.6050108@archonet.com> <24675.1121786346@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