Skip to main content

Data Types

Turso uses the same dynamic type system as SQLite, where values have types but columns do not enforce a single type (unless using STRICT tables). Every value stored in Turso belongs to one of five storage classes. Turso extends this system with custom types, composite types, and native array types for STRICT tables.

Storage Classes

Type Affinity

When a column is declared with a type name, Turso assigns a type affinity to that column. Type affinity is a recommendation for how to store values, not a strict constraint (unless using STRICT tables). Turso uses the same affinity rules as SQLite.

Affinity Determination Rules

The type affinity of a column is determined by the declared type name, using these rules applied in order:

Type Conversions

When a value is inserted into a column, Turso attempts to convert the value to the column’s affinity:
  • INTEGER affinity: If the value is TEXT or REAL that looks like an integer, Turso converts the value to INTEGER
  • REAL affinity: If the value is TEXT that looks like a number, Turso converts to REAL. If the value is an integer, Turso converts to REAL
  • NUMERIC affinity: Turso tries INTEGER first, then REAL, then keeps as TEXT
  • TEXT affinity: Integer and REAL values are converted to their text representation
  • BLOB affinity: No conversion is attempted

STRICT Tables

STRICT tables enforce type checking at the storage layer. Every value inserted into a STRICT table must match the declared column type or be convertible to the column type.

Allowed Types in STRICT Tables

STRICT tables only allow these base type names:
Turso Extension: STRICT tables also accept custom type names, composite types (STRUCT and UNION), and array types. Any base type can be turned into an array column by appending [] to the type name (e.g., INTEGER[], TEXT[]). Arrays, custom types, and composite types are Turso-specific features.

Custom Types

Turso Extension: Custom types are a Turso-specific feature not available in SQLite. Custom types work only with STRICT tables. This feature is experimental and must be enabled before use.
Custom types let you define how values are encoded before storage and decoded when read, enforce domain constraints at the storage layer, attach operators, and provide defaults. Custom types are declared with the CREATE TYPE statement.

Built-in Custom Types

Turso provides several built-in custom types available in STRICT tables:
For the full custom types reference including ENCODE/DECODE, operators, parametric types, and validation, see CREATE TYPE.

Composite Types: STRUCT and UNION

Turso also supports composite types: STRUCT (named product type) and UNION (discriminated union). These let you store structured data in a single column and access it with dot notation.
For the full composite types reference, see CREATE TYPE — Composite Types.

Array Types

Turso Extension: Array types are a Turso-specific feature not available in SQLite. Array columns work only with STRICT tables.
Array columns store ordered collections of values. Declare them by appending [] to any base type name:
Multi-dimensional arrays are supported with multiple bracket pairs:
Arrays can be inserted using the ARRAY[...] constructor or as JSON text:
Arrays are displayed as JSON arrays on output. Element types are validated against the declared base type — for example, an INTEGER[] column rejects non-numeric text elements. For the full set of array functions, operators, and subscript syntax, see Array Functions.

Inspecting Types

List all available types (built-in and custom):
All types are also available through the sqlite_turso_types virtual table:

Comparison and Sorting

Turso uses the same comparison rules as SQLite. Values of different storage classes are ordered as:
  • NULL values are considered less than any other value
  • INTEGER and REAL values are compared numerically
  • TEXT values are compared using the column’s collation sequence (default: BINARY)
  • BLOB values are compared using memcmp()

See Also