Re: Casting Integer to Boolean in assignment

Поиск
Список
Период
Сортировка
От Geoff Winkless
Тема Re: Casting Integer to Boolean in assignment
Дата
Msg-id CAEzk6ff-420-Ny_H0nWTM1nxxxcYQ4edJdG4Myz1hjxyCHPGAQ@mail.gmail.com
обсуждение исходный текст
Ответ на Casting Integer to Boolean in assignment  (Alexandre GRAIL <postgresql.general@augure.net>)
Ответы Re: Casting Integer to Boolean in assignment  (Thomas Kellerer <spam_eater@gmx.net>)
Re: Casting Integer to Boolean in assignment  (Alexandre GRAIL <postgresql.general@augure.net>)
Список pgsql-general
On Thu, 24 Jan 2019 at 11:04, Alexandre GRAIL
<postgresql.general@augure.net> wrote:
>
> And added to this weirdness is the fact that '1' or '0' (with quote) is OK.
>
The reason for that at least is that '1' and '0' are valid boolean values.

https://www.postgresql.org/docs/9.5/datatype-boolean.html

There's additional text describing why casts are chosen to be defined
as implicit or not here

https://www.postgresql.org/docs/9.5/typeconv-overview.html

My own opinion is that non-0 should implicitly cast as true and 0
should cast as false. I just run

UPDATE pg_cast SET castcontext = 'i' WHERE oid IN (
 SELECT c.oid
 FROM pg_cast c
 inner join pg_type src ON src.oid = c.castsource
 inner join pg_type tgt ON tgt.oid = c.casttarget
 WHERE (src.typname ILIKE '%int%' AND tgt.typname ILIKE 'bool%')
 OR (src.typname ILIKE 'bool%' AND tgt.typname ILIKE '%int%')
 OR (src.typname ILIKE 'bool%' AND tgt.typname ILIKE 'bit%')
 OR (src.typname ILIKE 'bit%' AND tgt.typname ILIKE 'bool%')
 OR (src.typname ILIKE 'bit%' AND tgt.typname ILIKE '%int')
);

when I install the system to solve this for my own uses.

Geoff


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

Предыдущее
От: Alexandre GRAIL
Дата:
Сообщение: Casting Integer to Boolean in assignment
Следующее
От: Thomas Kellerer
Дата:
Сообщение: Re: Casting Integer to Boolean in assignment