Skip to main content

Expressions

Expressions are combinations of values, operators, and functions that Turso evaluates to produce a result. Expressions appear in many SQL clauses including SELECT columns, WHERE conditions, ORDER BY, GROUP BY, HAVING, CHECK constraints, and DEFAULT values.

Literals

Numeric Literals

String Literals

String literals are enclosed in single quotes. To include a single quote within a string, use two consecutive single quotes:

Blob Literals

Blob literals are hexadecimal strings preceded by x or X:

NULL Literal

Boolean Literals

Turso does not have a separate boolean type. Use integers 0 (false) and 1 (true):

Operators

Arithmetic Operators

Integer division truncates toward zero. Use CAST or multiply by 1.0 for floating-point division:

Comparison Operators

All comparison operators return 1 (true), 0 (false), or NULL (if either operand is NULL).

Logical Operators

Bitwise Operators

String Concatenation

When either operand is an array, || performs array concatenation instead. See Array Operators.

Array Operators

Turso Extension: Array operators are a Turso-specific feature not available in SQLite.
The @> operator tests if the left array contains all elements of the right array. The && operator tests if two arrays share any common elements. Both return 1 (true) or 0 (false). Array comparison is element-wise from left to right. If all compared elements are equal, the shorter array is considered less than the longer one.
For the full reference, see Array Functions.

CAST Expression

The CAST expression converts a value to a specified type.
Turso Extension: In STRICT tables with custom types, CAST(value AS custom_type) applies the custom type’s ENCODE function. See CREATE TYPE for details.

COLLATE Expression

The COLLATE expression specifies a collation sequence for string comparison.
Built-in collation sequences:

Pattern Matching

LIKE Operator

The LIKE operator performs case-insensitive pattern matching (for ASCII characters). The % wildcard matches any sequence of characters, and _ matches any single character.

GLOB Operator

The GLOB operator performs case-sensitive pattern matching using Unix-style wildcards. * matches any sequence of characters, and ? matches any single character.

REGEXP Operator

The REGEXP operator performs regular expression matching. Requires the regexp extension (loaded by default).

BETWEEN Expression

The BETWEEN expression tests whether a value falls within an inclusive range.
The BETWEEN expression is equivalent to expression >= low AND expression <= high:

IN Expression

The IN expression tests whether a value matches any value in a list or subquery result.

EXISTS Expression

The EXISTS expression returns 1 if the subquery returns at least one row, and 0 otherwise.

IS NULL / IS NOT NULL

The IS NULL expression tests whether a value is NULL. Unlike = NULL, which always returns NULL, IS NULL returns 1 or 0.

IS DISTINCT FROM

The IS DISTINCT FROM expression compares two values, treating NULL as a comparable value.

CASE Expression

The CASE expression provides conditional logic within SQL expressions.

Simple CASE

Searched CASE

If no WHEN clause matches and there is no ELSE clause, the CASE expression returns NULL.

Scalar Subqueries

A subquery enclosed in parentheses that returns a single value can be used as an expression.
The subquery must return exactly one column and at most one row. If the subquery returns no rows, the expression evaluates to NULL.

RAISE Function

The RAISE function raises an error condition. In standard SQLite, RAISE can only be used inside triggers. In Turso, RAISE(ABORT, msg) can also be used outside triggers — in CHECK constraints, custom type ENCODE expressions, and standalone queries. The other forms (RAISE(IGNORE), RAISE(ROLLBACK, msg), RAISE(FAIL, msg)) are only valid inside triggers.

Operator Precedence

Operators are evaluated in the following order (highest precedence first): Use parentheses to override precedence when needed:

See Also