Re: Casting Integer to Boolean in assignment

Поиск
Список
Период
Сортировка
Искать
От
David G. Johnston
Тема
Re: Casting Integer to Boolean in assignment
Дата
Msg-id
CAKFQuwZXYgDxDLkB4a2jVn+bcuyxEWyROoKL8z-fwfrbS1pFgA@mail.gmail.com
Ответ на
Список
Дерево обсуждения
Casting Integer to Boolean in assignment Alexandre GRAIL <postgresql.general@augure.net>
Re: Casting Integer to Boolean in assignment Ron <ronljohnsonjr@gmail.com>
Re: Casting Integer to Boolean in assignment Adrian Klaver <adrian.klaver@aklaver.com>
Re: Casting Integer to Boolean in assignment Geoff Winkless <pgsqladmin@geoff.dj>
Re: Casting Integer to Boolean in assignment Thomas Kellerer <spam_eater@gmx.net>
Re: Casting Integer to Boolean in assignment Geoff Winkless <pgsqladmin@geoff.dj>
Re: Casting Integer to Boolean in assignment Alexandre GRAIL <postgresql.general@augure.net>
Re: Casting Integer to Boolean in assignment Laurenz Albe <laurenz.albe@cybertec.at>
Re: Casting Integer to Boolean in assignment "David G. Johnston" <david.g.johnston@gmail.com>
Re: Casting Integer to Boolean in assignment Geoff Winkless <pgsqladmin@geoff.dj>
Re: Casting Integer to Boolean in assignment Tom Lane <tgl@sss.pgh.pa.us>
Re: Casting Integer to Boolean in assignment Geoff Winkless <pgsqladmin@geoff.dj>
Re: Casting Integer to Boolean in assignment Adrian Klaver <adrian.klaver@aklaver.com>
Re: Casting Integer to Boolean in assignment Geoff Winkless <pgsqladmin@geoff.dj>
Re: Casting Integer to Boolean in assignment Adrian Klaver <adrian.klaver@aklaver.com>
Re: Casting Integer to Boolean in assignment Geoff Winkless <pgsqladmin@geoff.dj>
Re: Casting Integer to Boolean in assignment Adrian Klaver <adrian.klaver@aklaver.com>
Re: Casting Integer to Boolean in assignment Geoff Winkless <pgsqladmin@geoff.dj>
Re: Casting Integer to Boolean in assignment Alexandre GRAIL <postgresql.general@augure.net>
Re: Casting Integer to Boolean in assignment Geoff Winkless <pgsqladmin@geoff.dj>
Re: Casting Integer to Boolean in assignment Ron <ronljohnsonjr@gmail.com>
On Thu, Jan 24, 2019 at 4:04 AM Alexandre GRAIL
 wrote:
> But you *cannot* use 1 or 0 as valid input for boolean type when
> inserting or updating :
>
> test=# CREATE TABLE test1 (a boolean);
> CREATE TABLE
> test=# INSERT INTO test1 VALUES (1);
> ERROR:  column "a" is of type boolean but expression is of type integer
> LINE 1: INSERT INTO test1 VALUES (1);
>                                    ^
> HINT:  You will need to rewrite or cast the expression.
>
>
> This behavior cannot be changed, as this cast is hard coded with
> "Implicit?=no".
>
> And added to this weirdness is the fact that '1' or '0' (with quote) is OK.

Because '1' is the literal character 1 with an unknown type and so can
be (must be) assigned its initial real type from context.

1 is an integer, which is a real type

> So is there a reason to forbid 0 and 1 as valid boolean, without
> explicit cast ?

To assist developers in avoiding the writing of buggy queries.

David J.

В списке pgsql-general по дате отправления
От: bhargav kamineni
Дата:
Сообщение: log_min_duration_statement
От: Hellmuth Vargas
Дата:
FAQ