SQLite data types
The five SQLite storage classes, how declared types become affinities, STRICT tables, and how to store booleans, dates and money in SQLite.
Quick Answer
SQLite stores every value as one of five types: NULL, INTEGER, REAL, TEXT or BLOB. The type you declare on a column only sets its affinity, a preference SQLite applies when it can, so a column declared INTEGER still accepts 'abc'. To make SQLite enforce the types, add STRICT (SQLite 3.37+):
CREATE TABLE products (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
price REAL,
qty INTEGER,
photo BLOB
) STRICT;
There is no boolean, date or decimal type. Store booleans as 0 and 1, dates as ISO-8601 text or Unix seconds, and money as an integer number of cents. typeof(column) tells you what a row really holds.
Storage classes and type affinity
The same text value '42', inserted into six columns with different declared types, ends up stored four different ways:
CREATE TABLE t (a INTEGER, b TEXT, c REAL, d NUMERIC, e BLOB, f);
INSERT INTO t VALUES ('42', 42, '42', '42', '42', '42');
SELECT typeof(a), typeof(b), typeof(c), typeof(d), typeof(e), typeof(f) FROM t;
integer|text|real|integer|text|text
An INTEGER, REAL or NUMERIC column converts text that looks like a number. A TEXT column turns numbers into text. A BLOB column, or one with no type at all, keeps exactly what you gave it. When text can't be converted, it is stored as text: 'abc' in an INTEGER column is still 'abc'.
SQLite picks the affinity from the declared type name with five rules, checked in order. Any name works, which is why VARCHAR(255) or DATETIME don't cause an error:
| Declared type contains | Affinity | Examples |
|---|---|---|
INT | INTEGER | INT, INTEGER, BIGINT, TINYINT |
CHAR, CLOB or TEXT | TEXT | TEXT, VARCHAR(255), NCHAR(10) |
BLOB, or no type | BLOB | BLOB, a column with no type |
REAL, FLOA or DOUB | REAL | REAL, DOUBLE, FLOAT |
| Anything else | NUMERIC | NUMERIC, DECIMAL(10,2), BOOLEAN, DATE, DATETIME |
A length is never enforced: a VARCHAR(5) column stored 'abcdefghij' in full. Use CHECK (length(code) <= 5) if the limit matters.
In VisuaLeaf
See what each row really stores in VisuaLeaf
Open the .db file in VisuaLeaf, right-click the table and choose Tables Info to see each column's declared type, default and keys, and Show DDL for the full CREATE TABLE, including whether it ends in STRICT. The data grid shows each cell as it is actually stored, so a text value sitting in an INTEGER column stands out instead of hiding behind the declared type.
To count the types in a column, run this in the SQL editor:
SELECT typeof(price) AS stored_as, COUNT(*) AS n
FROM products
GROUP BY stored_as;
More than one row in the result means the column holds mixed types, which is worth fixing before you add STRICT or compare the column with a number. See VisuaLeaf for SQLite.
What we found testing this
- A column declared STRING drops leading zeros.
STRINGisn't one of the type names SQLite looks for, so it gets NUMERIC affinity. The ZIP code'02134'came back as the integer2134from aSTRINGcolumn and from anINTEGERcolumn, and as'02134'only fromTEXT. FLOATING POINTis an integer column. The rules check forINTfirst, andPOINTcontains it.'1e3'inserted into aFLOATING POINTcolumn was stored as the integer1000.- STRICT still converts text that looks like a number. In a STRICT table,
'42'went into an INTEGER column as42and2.0as2. Only values that can't be converted without loss were refused:'abc'failed withcannot store TEXT value in INTEGER column s.qtyand1.5withcannot store REAL value in INTEGER column s.qty. ANYmeans different things in STRICT and normal tables. In a STRICT table,ANYkept'042'as text. In a normal table,ANYis just an unknown type name, so it got NUMERIC affinity and stored'042'as42.'true'is not true. In aBOOLEANcolumn holdingTRUE,'true','1',1,'yes'and2,WHERE flagmatched 4 rows,WHERE flag = TRUEmatched 3 (2isn't equal to 1) andWHERE flag IS TRUEmatched 4. The strings'true'and'yes'stayed text and matched none of them.- Numbers in a TEXT column sort as text. Python inserted
10and9into a TEXT column, andORDER BYreturned'10'before'9'. - Large integers lose precision in Node. better-sqlite3 stored
9007199254740993ncorrectly, but reading it back returned9007199254740992. With.safeIntegers()on the statement it returned9007199254740993n.
STRICT tables
Add STRICT after the closing parenthesis. Each column must then have one of six types, and a value that doesn't fit is an error instead of being stored as something else:
| STRICT type | Accepts |
|---|---|
INT or INTEGER | Integers, and text or reals that convert to an integer exactly |
REAL | Reals, and integers (stored as reals) |
TEXT | Text, and numbers (stored as text) |
BLOB | Blobs only |
ANY | Anything, stored exactly as given |
NULL is allowed in every column unless it's NOT NULL. Other type names are refused when the table is created:
sqlite> CREATE TABLE s2 (d DATETIME) STRICT;
Parse error: unknown datatype for s2.d: "DATETIME"
sqlite> CREATE TABLE s6 (x) STRICT;
Parse error: missing datatype for s6.x
VARCHAR(10), NUMERIC and BOOLEAN were refused the same way. You can't add STRICT to an existing table: rebuild it as shown on the ALTER TABLE page. To check which tables are strict:
SELECT name, strict FROM pragma_table_list
WHERE type = 'table' AND name NOT LIKE 'sqlite_%';
A database with STRICT tables needs SQLite 3.37.0 or newer to read them. Check SELECT sqlite_version(); in every app and tool that opens the file, not just the one that creates it.
Booleans in SQLite
SQLite has no boolean type. TRUE and FALSE are keywords for 1 and 0 (SQLite 3.23+), and typeof(TRUE) returns integer. Use an INTEGER column with a CHECK so only 0 and 1 get in:
CREATE TABLE tasks (
id INTEGER PRIMARY KEY,
title TEXT NOT NULL,
done INTEGER NOT NULL DEFAULT 0 CHECK (done IN (0, 1))
);
INSERT INTO tasks (title, done) VALUES ('write docs', TRUE);
SELECT title FROM tasks WHERE done; -- or WHERE done = 1
With the CHECK, 2 failed with CHECK constraint failed: done IN (0, 1), and the string '1' was converted to 1 and accepted. Without the CHECK, a BOOLEAN column takes anything, including the text 'true', which is false in a WHERE clause.
Dates, money and other types SQLite lacks
| You want | Store it as | Why |
|---|---|---|
| Date or timestamp | TEXT 2026-11-26 14:30:00 (UTC) or INTEGER Unix seconds | The date functions read both. See date and time in SQLite |
| Money | INTEGER cents | SELECT 0.1 + 0.2 returned 0.30000000000000004 and 0.1 + 0.2 = 0.3 returned 0 |
| DECIMAL(10,2) | INTEGER cents, or TEXT if you only display it | It gets NUMERIC affinity: '19.99' was stored as the REAL 19.99 and '20.00' as the integer 20 |
| ZIP codes, phone numbers, IDs with leading zeros | TEXT | Any numeric affinity turns '02134' into 2134 |
| UUID | TEXT, or a 16-byte BLOB | BLOB is smaller, TEXT is readable in any viewer |
| JSON | TEXT | Query it with the JSON functions. See JSON in SQLite |
From Python and Node
Python's sqlite3 binds True and False as 1 and 0 and reads them back as integers, so convert with bool():
conn.execute("INSERT INTO tasks (title, done) VALUES (?, ?)", ("write docs", True))
done = [bool(row[0]) for row in conn.execute("SELECT done FROM tasks")] # [True, False]
A decimal.Decimal isn't supported at all: ProgrammingError: Error binding parameter 2: type 'decimal.Decimal' is not supported. Convert it to integer cents or a string first.
better-sqlite3 refuses booleans: binding true threw TypeError: SQLite3 can only bind numbers, strings, bigints, buffers, and null. Convert with Number(), and use .safeIntegers() for integers above Number.MAX_SAFE_INTEGER:
db.prepare('INSERT INTO tasks (title, done) VALUES (?, ?)').run('write docs', Number(true))
const big = db.prepare('SELECT id FROM events WHERE id = ?').safeIntegers()
big.get(9007199254740993n) // { id: 9007199254740993n }
JavaScript numbers are doubles, but better-sqlite3 binds whole numbers as integers: in a STRICT INTEGER column, 2 was accepted and 2.5 was refused.
Frequently Asked Questions
What data types does SQLite support?
SQLite stores values as NULL, INTEGER, REAL, TEXT or BLOB. Declared types such as VARCHAR, DATETIME or BOOLEAN are accepted but only set a type affinity, one of INTEGER, TEXT, BLOB, REAL or NUMERIC.
Does SQLite have a boolean type?
No. TRUE and FALSE are aliases for 1 and 0. Store booleans in an INTEGER column with CHECK (col IN (0, 1)) so other values are refused.
What is a STRICT table in SQLite?
A table created with STRICT after the column list (SQLite 3.37+). Each column must be INT, INTEGER, REAL, TEXT, BLOB or ANY, and a value that cannot be converted to the column type without loss is an error.
Does SQLite enforce VARCHAR length?
No. VARCHAR(5) gets TEXT affinity and stores text of any length. Add CHECK (length(col) <= 5) to enforce a limit.