Re: Cast jsonb to numeric, int, float, bool

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Cast jsonb to numeric, int, float, bool
Дата
Msg-id 29252.1520866819@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Cast jsonb to numeric, int, float, bool  (Nikita Glukhov <n.gluhov@postgrespro.ru>)
Ответы Re: Cast jsonb to numeric, int, float, bool  (Darafei "Komяpa" Praliaskouski <me@komzpa.net>)
Список pgsql-hackers
Nikita Glukhov <n.gluhov@postgrespro.ru> writes:
> On 01.03.2018 11:19, Darafei "Komяpa" Praliaskouski wrote:
>> I would expect some casts to be implicit, so that chaining with other 
>> functions is possible:

> I think that only cast to a numeric type can be made implicit, because 
> it does not lose precision.

I hadn't been following this thread particularly, but I happened to notice
this bit, and I thought I'd better pop up to say No Way.  There will be
*no* implicit casts from json to any numeric type.  We have learned the
hard way that implicit cross-category casts are dangerous.  See the
advice in the CREATE CAST man page:

    It is wise to be conservative about marking casts as implicit. An
    overabundance of implicit casting paths can cause PostgreSQL to choose
    surprising interpretations of commands, or to be unable to resolve
    commands at all because there are multiple possible interpretations. A
    good rule of thumb is to make a cast implicitly invokable only for
    information-preserving transformations between types in the same
    general type category. For example, the cast from int2 to int4 can
    reasonably be implicit, but the cast from float8 to int4 should
    probably be assignment-only. Cross-type-category casts, such as text
    to int4, are best made explicit-only.


            regards, tom lane


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: [patch] BUG #15005: ANALYZE can make pg_class.reltuples inaccurate.
Следующее
От: Pavel Stehule
Дата:
Сообщение: Re: Transform for pl/perl