Array Functions
Turso Extension: Array types and functions are a Turso-specific feature for working with ordered collections directly in SQL. These functions are not part of the SQLite standard. Array columns require STRICT tables.
Array Construction
ARRAY[] Literal
Constructs an array from a list of expressions.string_to_array
Splits a string into an array using a delimiter.
Returns: BLOB — an array value.
Element Access
Subscript Operator []
Access individual elements using zero-based indexing. Returns NULL for out-of-bounds or negative indices.Slice Operator [start:end]
Extract a sub-array using half-open range[start, end).
Scalar Functions
array_length
Returns the number of elements along a given dimension of an array.
Returns: INTEGER — the number of elements along
dimension. NULL if the input is NULL, if dimension < 1, or if dimension exceeds the array’s nesting depth.
For multi-dimensional arrays the walker peeks into element zero at each level, so values are reported as if every inner array at a given depth has the same length (the layout Turso materialises).
array_upper
Returns the upper bound (inclusive) of a given dimension of an array.
Returns: INTEGER — the upper bound of
dimension. NULL with the same conditions as array_length.
Turso arrays are always 1-indexed, so array_upper(arr, dim) is equivalent to array_length(arr, dim) for every valid input. The function is provided for PostgreSQL compatibility.
array_append
Appends an element to the end of an array.
Returns: BLOB — a new array with the element appended.
array_prepend
Prepends an element to the beginning of an array.
Returns: BLOB — a new array with the element prepended.
array_cat
Concatenates two arrays.
Returns: BLOB — a new array containing all elements from both arrays.
|| operator also works for array concatenation:
array_remove
Removes all occurrences of an element from an array.
Returns: BLOB — a new array with all occurrences of the element removed.
array_contains
Tests whether an array contains a specific element.
Returns: INTEGER — 1 if found, 0 if not found.
array_position
Returns the zero-based index of the first occurrence of an element.
Returns: INTEGER — the zero-based index, or NULL if not found.
array_slice
Extracts a sub-array by index range.
Returns: BLOB — a new array containing elements from
start to end - 1.
array_to_string
Joins array elements into a string with a delimiter.
Returns: TEXT — the joined string.
array_contains_all
Tests whether one array contains all elements of another.
Returns: INTEGER — 1 if all elements of
needles are found in haystack, 0 otherwise.
@> operator is an alias for this function. See Array Operators.
array_overlap
Tests whether two arrays share any common elements.
Returns: INTEGER — 1 if any element appears in both arrays, 0 otherwise.
array_overlaps is accepted as an alias. The && operator is also an alias. See Array Operators.
Aggregate Function
array_agg
Collects values from a group of rows into an array.
Returns: BLOB — an array containing one element per row in the group. Returns NULL for empty groups.
Array Operators
Containment: @>
Tests whether the left array contains all elements of the right array. Equivalent toarray_contains_all(left, right).
Overlap: &&
Tests whether two arrays share any common elements. Equivalent toarray_overlap(left, right).
Comparison: =, !=, <, >, <=, >=
Arrays support element-wise comparison. Elements are compared pairwise from left to right; if all compared elements are equal, the shorter array is considered less than the longer one.Concatenation: ||
When either operand is an array,|| performs array concatenation or element append/prepend instead of string concatenation.
Using operators in WHERE clauses
Subscript Assignment
Array elements can be updated individually using subscript syntax in UPDATE statements.Examples
Tagging system
Multi-dimensional arrays
Type checking
Array columns in STRICT tables validate element types on insert and update:See Also
- Data Types for array column type declarations
- CREATE TABLE for STRICT table requirements
- Expressions for array operator syntax
- Aggregate Functions for
array_agg