1.6. SQLite data type

发布时间 :2025-10-25 12:31:09 UTC      

The SQLite data type is a property that specifies 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 tables. SQLite uses a more general dynamic type system. In SQLite, the data type of a value is related to the value itself, not to its container.

1.6.1. SQLite storage class

Each value stored in the SQLite database has one of the following storage classes:

Storage class

Description

NULL

The value is a NULL value.

INTEGER

A value is a signed integer stored in 1, 2, 3, 4, 6, or 8 bytes depending on the size of the value.

REAL

Value is a floating-point value stored as an 8-byte IEEE floating-point number.

TEXT

The value is a text string stored using database encoding (UTF-8, UTF-16BE, or UTF-16LE).

BLOB

The value is an blob data that is stored entirely according to its input.

SQLite’s storage classes are slightly more common than data types. The INTEGER storage class, for example, contains six different integer data types of different lengths.

1.6.2. SQLite affinity (Affinity) type

SQLite supports the concept of affinity types for columns. Any column can still store any type of data, and when the data is inserted, the data in the field will give priority to the kinship type as the way to store the value. The current version of SQLite supports the following five kinship types:

Affinity type

Description

TEXT

Before being inserted, numeric data needs to be converted to text format and then inserted into the target field.

NUMERIC

当文本数据被插入到亲缘性为NUMERIC的字段中时,如果转换操作不会导致数据信息丢失以及完全可逆,那么SQLite就会将该文本数据转换为INTEGER或REAL类型的数据,如果转换失败,SQLite仍会以TEXT方式存储该数据。对于NULL或BLOB类型的新数据,SQLite将不做任何转换,直接以NULL或BLOB的方式存储该数据。需要额外说明的是,对于浮点格式的常量文本,如”30000.0”,如果该值可以转换为INTEGER同时又不会丢失数值信息,那么SQLite就会将其转换为INTEGER的存储方式。

INTEGER

For fields of kinship type INTEGER, the rule is the same as NUMERIC, the only difference is when the CAST expression is executed.

REAL

其规则基本等同于NUMERIC,唯一的差别是不会将”30000.0”这样的文本数据转换为INTEGER存储方式。

NONE

Without any conversion, the data is directly stored as the data type to which the data belongs.

1.6.3. SQLite affinity type (Affinity) and type name

The following table lists the various data type names that can be used when creating SQLite3 tables, as well as the corresponding affinity types:

Data type

Affinity type

  • INT

  • INTEGER

  • TINYINT

  • SMALLINT

  • MEDIUMINT

  • BIGINT

  • UNSIGNED BIG INT

  • INT2

  • INT8

INTEGER

  • CHARACTER (20)

  • VARCHAR (255)

  • VARYING CHARACTER (255)

  • NCHAR (55)

  • NATIVE CHARACTER (70)

  • NVARCHAR (100)

  • TEXT

  • CLOB

TEXT

  • BLOB

  • No datatype specified

NONE

  • REAL

  • DOUBLE

  • DOUBLE PRECISION

  • FLOAT

REAL

  • NUMERIC

  • DECIMAL (10dint 5)

  • BOOLEAN

  • DATE

  • DATETIME

NUMERIC

1.6.4. Boolean data type

SQLite does not have a separate Boolean storage class. Instead, Boolean values are stored as integers 0 (false) and 1 (true).

1.6.5. 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 class

Date format

TEXT

A date in the format “YYYY-MM-DD HH:MM:SS.SSS”.

REAL

The number of days beginning at noon GMT on November 24, 4714 BC.

INTEGER

The number of seconds from-01-01 00:00:00 UTC.

You can store dates and times in any of the above formats, and you can use the built-in date and time functions to convert different formats by.

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.