SQLite data types
SQLite has five storage classes: NULL, INTEGER, REAL, TEXT and BLOB.
A column’s declared type does not fix the class of each value in it. SQLite only gives the column a type affinity, which is a preference for one class.
In the tables below, Supported means TableAI shows the value in the grid and lets you edit it where the column allows editing.
What are the SQLite storage classes?
Section titled “What are the SQLite storage classes?”| Storage class | What it stores | TableAI |
|---|---|---|
NULL |
An absent value, distinct from empty text or zero. | Supported |
INTEGER |
A signed whole number, stored in 1, 2, 3, 4, 6 or 8 bytes depending on its size. | Supported |
REAL |
An 8-byte IEEE floating-point number. | Supported |
TEXT |
A string in the database encoding: UTF-8, UTF-16LE or UTF-16BE. | Supported |
BLOB |
Bytes, stored exactly as given. | Supported |
Which declared types does SQLite accept?
Section titled “Which declared types does SQLite accept?”SQLite accepts any type name in a column definition. It chooses the column’s affinity from the name:
- A name containing
INTgetsINTEGERaffinity. - A name containing
CHAR,CLOBorTEXTgetsTEXTaffinity. - A name containing
BLOB, or no type at all, getsBLOBaffinity. - A name containing
REAL,FLOAorDOUBgetsREALaffinity. - Any other name gets
NUMERICaffinity.
| Affinity | Common declared names | TableAI |
|---|---|---|
INTEGER |
INT, INTEGER, TINYINT, SMALLINT, MEDIUMINT, BIGINT, UNSIGNED BIG INT, INT2, INT8 |
Supported |
TEXT |
CHARACTER(20), VARCHAR(255), VARYING CHARACTER(255), NCHAR(55), NATIVE CHARACTER(70), NVARCHAR(100), TEXT, CLOB |
Supported |
BLOB |
BLOB, or no declared type |
Supported |
REAL |
REAL, DOUBLE, DOUBLE PRECISION, FLOAT |
Supported |
NUMERIC |
NUMERIC, DECIMAL(10,5), BOOLEAN, DATE, DATETIME |
Supported |
A STRICT table accepts only INT, INTEGER, REAL, TEXT, BLOB and ANY as column types, and rejects a value of the wrong class.
How does SQLite store dates, booleans and JSON?
Section titled “How does SQLite store dates, booleans and JSON?”SQLite has no separate date, boolean or JSON type. The application chooses the representation:
| Kind of value | How SQLite stores it | TableAI |
|---|---|---|
| Boolean | An INTEGER: 0 for false, 1 for true |
Supported |
| Date and time | TEXT in ISO 8601 form, a REAL Julian day number, or an INTEGER Unix timestamp |
Supported |
| JSON | TEXT, including JSON arrays |
Supported |
Confirm the application’s format, time zone and numeric unit before changing a date or timestamp value. A column name alone does not establish those rules. Preserve the document’s syntax when editing JSON. Use Cell Value or Row Detail to inspect longer values.
Numbers that require exact arithmetic
Section titled “Numbers that require exact arithmetic”SQLite real numbers are approximate. For exact amounts, choose a representation that fits your application’s rules, such as integer minor units. Keep that representation consistent when importing data or writing SQL.
Edit and transfer values
Section titled “Edit and transfer values”The data editing guide explains the separate actions for NULL, defaults and empty text. For binary values, the results guide covers saving bytes and selecting replacement files.
Use import and export to choose file formats and representations for NULL and binary data. Check the destination column types when moving rows to another database.