Re: Casting Integer to Boolean in assignment - Mailing list pgsql-general

From Adrian Klaver
Subject Re: Casting Integer to Boolean in assignment
Date
Msg-id 984fa130-e8a1-6cb0-b7f8-f57e853f8dfd@aklaver.com
Whole thread Raw
In response to Re: Casting Integer to Boolean in assignment  (Geoff Winkless <pgsqladmin@geoff.dj>)
Responses Re: Casting Integer to Boolean in assignment  (Geoff Winkless <pgsqladmin@geoff.dj>)
List pgsql-general
On 1/24/19 7:48 AM, Geoff Winkless wrote:
> On Thu, 24 Jan 2019 at 15:40, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
>> delete from delete_test where
>>
>> and then forget the 'field =' part. Though my more common mistake along
>> that line is:
>>
>> delete from delete_test;
>>
>> At any rate, if it can be done it will be done.
> 
> If you follow that logic, then having a single boolean test at all
> should be invalid.
> 
> CREATE TABLE mytest (myval char (1));
> INSERT INTO mytest VALUES ('a'),('b'),('c'),('s'),('t');
> DELETE FROM mytest WHERE 't';
> SELECT * FROM mytest;
>   myval
> -------
> (0 rows)

People are going to make mistakes that is a given. Eliminating a boolean 
test is not going to change that. Where this particular sub-thread 
started was with this from a previous post of yours:

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

That opens an infinite number of values that could be seen as True. That 
in turn leads to greater chance of fat-thumbing yourself into an oops. 
Like you say it is a matter of opinion. The projects opinion is here:

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

and it works for me.

> 
> Geoff
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com


pgsql-general by date:

Previous
From: bhargav kamineni
Date:
Subject: Re: log_min_duration_statement
Next
From: Geoff Winkless
Date:
Subject: Re: Casting Integer to Boolean in assignment