Re: Old question - failed to find conversion function from

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Richard Huxton <dev(at)archonet(dot)com>
Cc: ilejn(at)yandex(dot)ru, pgsql-general(at)postgresql(dot)org
Subject: Re: Old question - failed to find conversion function from
Date: 2005-07-19 15:19:06
Message-ID: 24675.1121786346@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-general

Richard Huxton <dev(at)archonet(dot)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

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Gopal Srinivasa 2005-07-19 15:35:17 Re: pg_restore hangs on 'some' HP-UX machines
Previous Message Ilja Golshtein 2005-07-19 15:01:05 Re: Old question - failed to find conversion function from "unknown"

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2005-07-19 15:22:58 Re: Hot to restrict access to subset of data
Previous Message Ilja Golshtein 2005-07-19 15:01:05 Re: Old question - failed to find conversion function from "unknown"