Search Postgresql Archives

Re: Old question - failed to find conversion function from

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Richard Huxton <dev@xxxxxxxxxxxx> 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

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux