Functions
A scalar function works at any position that accepts a value. That includes a
projection, a filter, a key of a GROUP BY, a default, and a check constraint.
A function also nests inside another function:
SELECT upper(trim(name)) AS display_name
FROM robots
WHERE abs(year - 2000) <= 5;
The name of a function is not case-sensitive.
Categories
- Session Functions
- String Functions
- Math Functions
- Hash Functions
- Date/Time Functions
- JSON Functions
- Regex Functions
- Conversion Functions
- Null Functions
- UUID Functions
- Object Id Functions
- Array Functions, which are
cardinality,array_length, andarray_contains - Sequence functions, which are
nextval,currval,lastval, andsetval - Vector functions, which are
octet_length,vector_dims,l2_distance,cosine_distance, andinner_product
Two rules worth your attention
A null propagates. Most functions return NULL when one argument is NULL.
Null Functions covers the exceptions, such as coalesce
and nullif. Each page of a category marks any other exception.
Some functions are volatile. Eight of them can return a different value at every
evaluation: gen_id(), gen_uuid_v4(), gen_uuid_v7(), current_timestamp(),
now(), current_date(), unix_timestamp(), and random(). That property
makes them useful as the default of a column. It also makes them unsafe in a
predicate that must stay stable across a scan.
The session functions are volatile for another reason. They vary by caller, not by row. They therefore bypass the result cache. You cannot use one as a default.
CamusDB evaluates the arguments before the call. It validates the number of the arguments and their types at the execution. It does not validate them at the parse.