On 3/2/18, J Decker <d3c...@gmail.com> wrote:
> On Fri, Mar 2, 2018 at 4:19 AM, Richard Hipp <d...@sqlite.org> wrote:
>
>> On 3/2/18, Olivier Mascia <o...@integral.be> wrote:
>> >
>> > What values will be considered FALSE, and hence will TRUE be NOT FALSE
>> > or
>> > equality to some other specific value?
>>
>> I have a note to provide additional documentation on this before the
>> release.
>>
>> In short, a value is FALSE is, when converted into a floating point
>> number via CAST(x AS REAL) it has a value of 0.0.
>>
>> It used to be (https://www.sqlite.org/src/info/36fae083b450e3af) that
>> sometimes FALSE was determined by CAST(x AS INTEGER).  This was
>> inconsistent.  Beginning with 3.23.0, FALSE is determined by CAST(x AS
>> REAL) in all cases.
>>
>> So in other words, it used to be that 0.5 was sometimes considered
>> TRUE and other times considered FALSE, depending on context.  It is
>> now always considered TRUE.
>>
>> Strings are TRUE or FALSE depending on whether or not they evaluate to
>> non-zero when converted.  '123xyz' is TRUE, but '0abc', 'abc', and ''
>> are all FALSE.
>>
>>
>> > Will insert into T values(FALSE) actually store integer 0 no matter
>> column
>> > affinity or will it follow affinity?
>>
>> No.  FALSE is merely an alias for 0.  Affinity still applies.  If the
>> column is of type TEXT, then it will store '0', not 0.
>>
>
> is NULL false?

No.  NULL is neither TRUE nor FALSE.  SQL (and SQLite) uses three-value logic.

NULL is TRUE -> FALSE
NULL is FALSE -> FALSE
NULL is NULL -> TRUE
TRUE is NULL -> FALSE
TRUE is TRUE -> TRUE
TRUE is FALSE -> FALSE
FALSE is NULL -> FALSE
FALSE is TRUE -> FALSE
FALSE is FALSE -> TRUE

Note the definition of the WHERE clause is that it causes all rows to
be returned where the condition is TRUE.  That means that it rejects
cases where the condition is either FALSE or NULL.  Likewise the CASE
statement groups NULL together with FALSE for its binary decisions.  I
didn't invent this - it is the way SQL works.

-- 
D. Richard Hipp
d...@sqlite.org
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to