Re: Old question - failed to find conversion function from

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Old question - failed to find conversion function from
Дата
Msg-id 24675.1121786346@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Old question - failed to find conversion function from  (Richard Huxton <dev@archonet.com>)
Ответы Re: Old question - failed to find conversion function from  ("Ilja Golshtein" <ilejn@yandex.ru>)
Список pgsql-general
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

В списке pgsql-general по дате отправления:

Предыдущее
От: "Ilja Golshtein"
Дата:
Сообщение: Re: Old question - failed to find conversion function from "unknown"
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Hot to restrict access to subset of data