# 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. 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 = anytype
anytype = anytype -> bool

Compare two values for equality.

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

Compare two values for inequality.

Copy
`db> `
`SELECT 3 != 3.14;`
`{true}`
operator
anytype ?= anytype
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.

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

Compare two (potentially empty) values for inequality.

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

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

Less than operator.

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

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

Greater than operator.

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

Copy
`db> `
`SELECT 1 > 2;`
`{false}`
Copy
`db> `
`SELECT 3 > 2;`
`{true}`
operator
anytype <= anytype
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.

Copy
`db> `
`SELECT 1 <= 2;`
`{true}`
Copy
`db> `
`SELECT 'aaa' <= 'bbb';`
`{true}`
operator
anytype >= anytype
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.

Copy
`db> `
`SELECT 1 >= 2;`
`{false}`
function
len()
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`.

Copy
`db> `
`SELECT len('foo');`
```{3}
```
Copy
`db> `
`SELECT len(b'bar');`
```{3}
```
Copy
`db> `
`SELECT len([2, 5, 7]);`
`{3}`
function
contains()
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.

Copy
`db> `
`SELECT contains('qwerty', 'we');`
```{true}
```
Copy
`db> `
`SELECT contains(b'qwerty', b'42');`
```{false}
```
Copy
`db> `
`SELECT contains([2, 5, 7, 2, 100], 2);`
`{true}`
function
find()
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`.

Copy
`db> `
`SELECT find('qwerty', 'we');`
```{1}
```
Copy
`db> `
`SELECT find(b'qwerty', b'42');`
```{-1}
```
Copy
`db> `
`SELECT find([2, 5, 7, 2, 100], 2);`
```{0}
```
Copy
`db> `
`SELECT find([2, 5, 7, 2, 100], 2, 1);`
`{3}`
function
round()
std::round(value: int64) -> float64std::round(value: float64) -> float64std::round(value: bigint) -> bigintstd::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:

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

`decimal` tie is rounded away from 0:

Copy
`db> `
`SELECT round(1.2n);`
```{1n}
```
Copy
`db> `
`SELECT round(1.5n);`
```{2n}
```
Copy
`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.

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

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

Copy
`db> `
`SELECT random();`
`{0.62649393780157}`