SQL
5 min read
BEGINNER
Boolean and binary
Quick AnswerBoolean values express true or false (and may be NULL). Binary values store bytes rather than characters, such as a file fragment.
Core idea
Boolean values express true or false (and may be NULL). Binary values store bytes rather than characters, such as a file fragment.
Minimal example
sql
SELECT TRUE, FALSE, typeof(TRUE);Expected SQLite rows:
text
1 | 0 | integerHow it works
PostgreSQL has BOOLEAN and BYTEA. SQLite stores TRUE and FALSE as integer 1 and 0; a BOOLEAN declaration alone does not restrict values to those two. SQLite BLOB literals use X followed by quoted hexadecimal pairs; PostgreSQL BYTEA has different input syntax. SQLite hex converts bytes to hexadecimal text.
Practical example
sql
SELECT hex(X'0041FF'), length(X'0041FF');Expected SQLite rows:
text
0041FF | 3Common mistake and practice
Do not confuse text containing hex digits with bytes. Compare length of X'4142' and the string '4142'.