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 byx or X:
NULL Literal
Boolean Literals
Turso does not have a separate boolean type. Use integers0 (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.
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.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.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 returns1 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
Scalar Subqueries
A subquery enclosed in parentheses that returns a single value can be used as an expression.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
- Data Types for storage classes and type affinity
- Scalar Functions for built-in functions usable in expressions
- SELECT for using expressions in queries