Generic Functions and Operators

anytype = anytype

Compare two values for equality.

anytype != anytype

Compare two values for inequality.

anytype ?= anytype

Compare two (potentially empty) values for equality.

anytype ?!= anytype

Compare two (potentially empty) values for inequality.

anytype < anytype

Less than operator.

anytype > anytype

Greater than operator.

anytype <= anytype

Less or equal operator.

anytype >= anytype

Greater or equal operator.

anytype IF bool ELSE anytype

Conditionally provide one or the other result.

len()

A polymorphic function to calculate a "length" of its first argument.

contains()

A polymorphic function to test if a sequence contains a certain element.

find()

A polymorphic function to find index of an element in a sequence.

round()

Round to the nearest value.

random()

Return a pseudo-random number in the range 0.0 <= x < 1.0.

operator anytype IF bool ELSE anytype -> anytype

Conditionally provide one or the other result.

left_expr IF condition ELSE right_expr

If condition is true, then the value of the IF..ELSE expression is the value of left_expr, if condition is false, the result is the value of right_expr.

db> 
SELECT 'hello' IF 2 * 2 = 4 ELSE 'bye';
{'hello'}

IF..ELSE expressions can be chained when checking multiple conditions is necessary:

db> 
... 
... 
... 
... 
WITH color := 'yellow'
SELECT 'Apple' IF color = 'red' ELSE
       'Banana' IF color = 'yellow' ELSE
       'Orange' IF color = 'orange' ELSE
       'Other';
{'Banana'}
operator anytype = anytype -> bool

Compare two values for equality.

db> 
SELECT 3 = 3.0;
{true}
db> 
SELECT [1, 2] = [1, 2];
{true}
db> 
SELECT (x := 1, y := 2) = (x := 1, y := 2);
{true}
db> 
SELECT 'hello' = 'hello';
{true}
operator anytype != anytype -> bool

Compare two values for inequality.

db> 
SELECT 3 != 3.14;
{true}
operator OPTIONAL anytype ?= OPTIONAL anytype -> bool

Compare two (potentially empty) values for equality.

Works the same as regular =, but also allows comparing {}. Two {} are considered equal.

db> 
SELECT {1} ?= {1.0};
{true}
db> 
SELECT {1} ?= <int64>{};
{false}
db> 
SELECT <int64>{} ?= <int64>{};
{true}
operator OPTIONAL anytype ?!= OPTIONAL anytype -> bool

Compare two (potentially empty) values for inequality.

Works the same as regular =<NEQ>, but also allows comparing {}. Two {} are considered equal.

db> 
SELECT {2} ?!= {2};
{false}
db> 
SELECT {1} ?!= <int64>{};
{true}
db> 
SELECT <bool>{} ?!= <bool>{};
{false}
operator anytype < anytype -> bool

Less than operator.

Return true if the value of the left expression is less than the value of the right expression.

db> 
SELECT 1 < 2;
{true}
db> 
SELECT 2 < 2;
{false}
operator anytype > anytype -> bool

Greater than operator.

Return true if the value of the left expression is greater than the value of the right expression.

db> 
SELECT 1 > 2;
{false}
db> 
SELECT 3 > 2;
{true}
operator anytype <= anytype -> bool

Less or equal operator.

Return true if the value of the left expression is less than or equal to the value of the right expression.

db> 
SELECT 1 <= 2;
{true}
db> 
SELECT 'aaa' <= 'bbb';
{true}
operator anytype >= anytype -> bool

Greater or equal operator.

Return true if the value of the left expression is greater than or equal to the value of the right expression.

db> 
SELECT 1 >= 2;
{false}
function std::len(value: str) -> int64std::len(value: bytes) -> int64std::len(value: array<anytype>) -> int64

A polymorphic function to calculate a “length” of its first argument.

Return the number of characters in a str, or the number of bytes in bytes, or the number of elements in an array.

db> 
SELECT len('foo');
{3}
db> 
SELECT len(b'bar');
{3}
db> 
SELECT len([2, 5, 7]);
{3}
function std::contains(haystack: str, needle: str) -> boolstd::contains(haystack: bytes, needle: bytes) -> boolstd::contains(haystack: array<anytype>, needle: anytype) -> bool

A polymorphic function to test if a sequence contains a certain element.

When the haystack is str or bytes, return true if needle is contained as a subsequence in it and false otherwise.

When the haystack is an array, return true if the array contains the specified element and false otherwise.

db> 
SELECT contains('qwerty', 'we');
{true}
db> 
SELECT contains(b'qwerty', b'42');
{false}
db> 
SELECT contains([2, 5, 7, 2, 100], 2);
{true}
function std::find(haystack: str, needle: str) -> int64std::find(haystack: bytes, needle: bytes) -> int64std::find(haystack: array<anytype>, needle: anytype, from_pos: int64 = 0) -> int64

A polymorphic function to find index of an element in a sequence.

When the haystack is str or bytes, return the index of the first occurrence of needle in it.

When the haystack is an array, return the index of the first occurrence of the specific needle element. For array inputs it is also possible to provide an optional from_pos argument to specify the position from which to start the search.

If the needle is not found, return -1.

db> 
SELECT find('qwerty', 'we');
{1}
db> 
SELECT find(b'qwerty', b'42');
{-1}
db> 
SELECT find([2, 5, 7, 2, 100], 2);
{0}
db> 
SELECT find([2, 5, 7, 2, 100], 2, 1);
{3}
function std::round(value: int64) -> float64std::round(value: float64) -> float64std::round(value: decimal) -> decimalstd::round(value: decimal, d: int64) -> decimal

Round to the nearest value.

There’s a difference in how ties (which way 0.5 is rounded) are handled depending on the type of the input value.

float64 tie is rounded to the nearest even number:

db> 
SELECT round(1.2);
{1}
db> 
SELECT round(1.5);
{2}
db> 
SELECT round(2.5);
{2}

decimal tie is rounded away from 0:

db> 
SELECT round(1.2n);
{1n}
db> 
SELECT round(1.5n);
{2n}
db> 
SELECT round(2.5n);
{3n}

Additionally, when rounding a decimal value an optional argument d can be provided to specify to what decimal point the value must to be rounded.

db> 
SELECT round(163.278n, 2);
{163.28n}
db> 
SELECT round(163.278n, 1);
{163.3n}
db> 
SELECT round(163.278n, 0);
{163n}
db> 
SELECT round(163.278n, -1);
{160n}
db> 
SELECT round(163.278n, -2);
{200n}
function std::random() -> float64

Return a pseudo-random number in the range 0.0 <= x < 1.0.

db> 
SELECT random();
{0.62649393780157}