I know about the boolean
column type, but is there a boolean
literal in SQLite? In other languages, this might be true
or false
. Obviously, I can use 0
and 1
, but I tend to avoid so-called "magic numbers" where possible.
From this list, it seems like it might exist in other SQL implementations, but not SQLite. (I'm using SQLite 3.6.10, for what it's worth.)
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:
dbfiddle.com demo
The question is explicitly not about the column type (i.e storage-wise) but the use of
TRUE
andFALSE
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
norFALSE
, 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:
I noticed in sqlite for android, I can declare a Boolean column type with no error and its seems to work fine. I also tried defining the column as 'int' and storing java boolean values. I downloaded the db and confirmed I'm writing "true" in the column. I think it just works.