Is there a boolean literal in SQLite?

前端 未结 12 1857
逝去的感伤
逝去的感伤 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:35

    The question is explicitly not about the column type (i.e storage-wise) but the use of TRUE and FALSE literals (i.e. parser-wise), which are SQL-compliant as per the PostgreSQL keywords documentation (which happens to also include SQL-92, SQL:2008 and SQL:2011 columns in the reference table).

    The SQLite documentation lists all supported keywords, and this list contains neither TRUE nor FALSE, hence SQLite sadly is non-compliant in that regard.

    You can also test it easily and see how the parser barfs as it wants the token to be a column name:

    $ sqlite3 :memory:
    SQLite version 3.14.0 2016-07-26 15:17:14
    sqlite> CREATE TABLE foo (booleanish INT);
    sqlite> INSERT INTO foo (booleanish) VALUES (TRUE);
    Error: no such column: TRUE
    

提交回复
热议问题