SQLite Data Types: Storage Classes and Type Affinity
SQLite uses dynamic typing: each stored value has a storage class, while a column’s declared type determines its preferred type affinity. These are different concepts. In a regular table, the declared column type does not always determine the storage class of every value.
The five SQLite storage classes
| Storage class | What it stores | Related guide |
|---|---|---|
NULL |
Missing or unknown values | NULL |
INTEGER |
Signed whole numbers, up to 64 bits | INTEGER |
REAL |
Approximate IEEE 754 binary64 numbers | REAL |
TEXT |
Text in the database encoding | TEXT |
BLOB |
Raw bytes without text conversion | BLOB |
There is no NUMERIC storage class. NUMERIC is one of the five affinities, along with TEXT, INTEGER, REAL, and BLOB. See NUMERIC affinity for why a DECIMAL(10,2) declaration does not guarantee fixed decimal precision.
How column affinity changes inserted values
In a normal SQLite table, a column’s affinity influences conversions when a value is inserted. For example, a numeric-looking string may become an integer in an INTEGER column, while a number may become text in a TEXT column.
CREATE TABLE demo (
quantity INTEGER,
price NUMERIC,
label TEXT
);
INSERT INTO demo VALUES ('12', '12.50', 42);
SELECT typeof(quantity) AS quantity_type,
typeof(price) AS price_type,
typeof(label) AS label_type
FROM demo;
quantity_type price_type label_type
------------- ---------- ----------
integer real textThe typeof() function reports each value’s actual storage class, not its column’s declared type. SQLite also supports STRICT tables for stronger type enforcement; their allowed declared types differ from ordinary tables.
Choose a type for your data
Use INTEGER for exact whole numbers and integer minor units such as cents. Use REAL for measurements where floating-point approximation is acceptable. Use TEXT for names and other strings, and BLOB for binary data. For dates and times, SQLite commonly uses TEXT, REAL, or INTEGER representations rather than a separate date storage class.
Run the example in the SQLite Playground and change the inserted values to observe affinity conversions. The official SQLite datatype reference explains the complete rules, including STRICT tables and type-name matching.
-
BLOB
Understand SQLite’s BLOB storage class and BLOB affinity. Insert binary data with hex literals or Python bytes, then verify it with typeof(), length(), and hex(). -
INTEGER
In SQLite, theINTEGERdata type is used to store integer values. -
NULL
In SQLite, the NULL data type is used to represent a missing or unknown value. -
NUMERIC
Learn what SQLite NUMERIC affinity does, why NUMERIC(10,2) is not fixed precision, and how INTEGER, REAL, TEXT, and NULL values are stored. -
REAL
Learn SQLite REAL affinity, floating-point precision, why 0.1 + 0.2 may not equal 0.3, and when to store exact values as INTEGER. -
TEXT
TEXTis a data type in SQLite used for storing text strings.