On Thu, Jan 24, 2019 at 4:04 AM Alexandre GRAIL
<postgresql.general@augure.net> 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.