Utility Functions
Utility Functions
General-purpose functions for data manipulation, control flow, and type handling. The examples are self-contained. Geographic operations require backend spatial support; coordinate systems and distance units depend on the database.
Parenthetical
Used for explicit grouping of expressions, primarily to control the order of operations. Does not change the value, type, or purpose of the enclosed expression.
Coalesce
Returns the first non-null value from its list of arguments. All arguments must be of compatible types. Returns NULL if all arguments are NULL.
Cast
Converts an expression to a target type. Write expression::type or cast(expression as type).
IS_NULL
Use expression is null to test for a missing value. IS_NULL is the operation name, not a callable function.
BOOL
Converts a value to boolean. Numeric 0 is false and 1 is true. Accepted string representations and invalid-value errors depend on the backend; arbitrary non-empty strings are not necessarily true.
CASE
Evaluates a series of conditions and returns a result based on the first condition that evaluates to true. Syntax: `CASE WHEN condition1 THEN result1 [WHEN condition2 THEN result2 ...] [ELSE default_result] END`. All result expressions must have compatible types.
NULLIF
Returns NULL if the two arguments are equal, otherwise it returns the first argument.
HASH
Computes a string hash using an unquoted algorithm keyword: md5, sha1, sha256, or sha512. Algorithm availability depends on the backend.
GEO_POINT
Creates a geographical point from longitude (x) followed by latitude (y).
GEO_DISTANCE
Calculates the distance between two geographical points. Units depend on the backend and coordinate system; do not assume the result is in meters.