Is there a boolean literal in SQLite?

前端 未结 12 1847
逝去的感伤
逝去的感伤 2020-12-04 20:43

I know about the boolean column type, but is there a boolean literal in SQLite? In other languages, this might be true

12条回答
  •  天命终不由人
    2020-12-04 21:31

    Is there a boolean literal in SQLite?

    As stated in Justin Ethier's answer, SQLite does not have specific data type for boolean. But starting from SQLite 3.23.0 it supports true/false literals:

    1. Recognize TRUE and FALSE as constants. (For compatibility, if there exist columns named "true" or "false", then the identifiers refer to the columns rather than Boolean constants.)

    2. Support operators IS TRUE, IS FALSE, IS NOT TRUE, and IS NOT FALSE.

    SELECT true AS t, false AS f;
    
    SELECT 'condition is true'
    WHERE 1 IS NOT FALSE;
    
    CREATE TABLE a (id INT, b BOOLEAN DEFAULT(TRUE));
    INSERT INTO a(id) VALUES(100);
    SELECT * FROM a;
    -- id  b
    -- 100 1
    
    SELECT * FROM a WHERE true;
    -- id  b
    -- 100 1
    

    dbfiddle.com demo

提交回复
热议问题