SQLite data type
SQLite data type is an attribute used to specify the data type of any object. Every column, variable and expression in SQLite has an associated data type.
You can use these data types while creating a table. SQLite uses a more general dynamic type system. In SQLite, the data type of a value is related to the value itself, not its container.
SQLite Storage Classes
Every value stored in a SQLite database has one of the following storage classes:
Storage Class | Description |
---|---|
NULL | The value is a NULL value. |
INTEGER | The value is a signed integer stored in 1, 2, 3, 4, 6, or 8 bytes depending on the size of the value. |
REAL | The value is a floating point value stored as an 8-byte IEEE floating point number. |
TEXT | The value is a text string stored using the database encoding (UTF-8, UTF-16BE, or UTF-16LE). |
BLOB | The value is a blob of data stored entirely based on its input. |
#SQLite's storage classes are slightly more general than data types. The INTEGER storage class, for example, contains 6 different integer data types of varying lengths.
SQLite Affinity Types
SQLite supports the type affinity concept on columns. Any column can still store any type of data, but the column's preferred storage class is its affinity. In a SQLite3 database, each table's columns are assigned one of the following types of affinity:
Affinity | Description |
---|---|
TEXT | This column uses the storage class NULL, TEXT or BLOB to store all data. |
NUMERIC | This column can contain values using all five storage classes. |
INTEGER | Same as column with NUMERIC affinity, with exception in CAST expression. |
REAL | Similar to columns with NUMERIC affinity, except that it forces integer values to be converted to floating point representation. |
NONE | Columns with affinity NONE will not prioritize which storage class to use, nor will they try to force data from one storage class to another. kind. |
SQLite Affinity and type names
The following table lists the various data type names that can be used when creating SQLite3 tables, and also shows the corresponding application Affinity:
Data Type | Affinity |
---|---|
| |
| |
##BLOB
| |
REAL
| |
NUMERIC
| Boolean data type |
Date and Time data types
SQLite does not have a separate storage class for storing dates and/or times, but SQLite can store dates and times as TEXT, REAL, or INTEGER values.
Storage classTEXT | |
---|---|
REAL | |
INTEGER | |
You can store dates and times in any of the above formats, and you can use the built-in date and time functions to freely convert between different formats. |