# Generic Functions and Operators​

 anytype = anytype Compares two values for equality. anytype != anytype Compares two values for inequality. anytype ?= anytype Compares two (potentially empty) values for equality. anytype ?!= anytype Compares 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() Returns the number of elements of a given value. contains() Returns true if the given sub-value exists within the given value. find() Returns the index of a given sub-value in a given value.

In EdgeQL, any value can be compared to another as long as their types are compatible.

operator

anytype = anytype
anytype = anytype -> bool

Compares two values for equality.

Copy
`db> `
`select 3 = 3.0;`
`{true}`
Copy
`db> `
`select 3 = 3.14;`
`{false}`
Copy
`db> `
`select [1, 2] = [1, 2];`
`{true}`
Copy
`db> `
`select (1, 2) = (x := 1, y := 2);`
`{true}`
Copy
`db> `
`select (x := 1, y := 2) = (a := 1, b := 2);`
`{true}`
Copy
`db> `
`select 'hello' = 'world';`
`{false}`

When either operand in an equality comparison is an empty set, the result will not be a `bool` but instead an empty set.

Copy
`db> `
`select true = <bool>{};`
`{}`

If one of the operands in an equality comparison could be an empty set, you may want to use the `coalescing equality` operator (`?=`) instead.

operator

anytype != anytype
anytype != anytype -> bool

Compares two values for inequality.

Copy
`db> `
`select 3 != 3.0;`
`{false}`
Copy
`db> `
`select 3 != 3.14;`
`{true}`
Copy
`db> `
`select [1, 2] != [2, 1];`
`{false}`
Copy
`db> `
`select (1, 2) != (x := 1, y := 2);`
`{false}`
Copy
`db> `
`select (x := 1, y := 2) != (a := 1, b := 2);`
`{false}`
Copy
`db> `
`select 'hello' != 'world';`
`{true}`

When either operand in an inequality comparison is an empty set, the result will not be a `bool` but instead an empty set.

Copy
`db> `
`select true != <bool>{};`
`{}`

If one of the operands in an inequality comparison could be an empty set, you may want to use the `coalescing inequality` operator (`?!=`) instead.

operator

anytype ?= anytype
optional anytype ?= optional anytype -> bool

Compares two (potentially empty) values for equality.

This works the same as a regular `=` operator, but also allows comparing an empty `{}` set. Two empty sets 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

Compares two (potentially empty) values for inequality.

This works the same as a regular `=` operator, but also allows comparing an empty `{}` set. Two empty sets 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.

The operator returns `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}`
Copy
`db> `
`select 'hello' < 'world';`
`{true}`
Copy
`db> `
`select (1, 'hello') < (1, 'world');`
`{true}`

operator

anytype > anytype
anytype > anytype -> bool

Greater than operator.

The operator returns `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}`
Copy
`db> `
`select 'hello' > 'world';`
`{false}`
Copy
`db> `
`select (1, 'hello') > (1, 'world');`
`{false}`

operator

anytype <= anytype
anytype <= anytype -> bool

Less or equal operator.

The operator returns `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 2 <= 2;`
`{true}`
Copy
`db> `
`select 3 <= 2;`
`{false}`
Copy
`db> `
`select 'hello' <= 'world';`
`{true}`
Copy
`db> `
`select (1, 'hello') <= (1, 'world');`
`{true}`

operator

anytype >= anytype
anytype >= anytype -> bool

Greater or equal operator.

The operator returns `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}`
Copy
`db> `
`select 2 >= 2;`
`{true}`
Copy
`db> `
`select 3 >= 2;`
`{true}`
Copy
`db> `
`select 'hello' >= 'world';`
`{false}`
Copy
`db> `
`select (1, 'hello') >= (1, 'world');`
`{false}`

function

len()
std::len(value: str) -> int64std::len(value: bytes) -> int64std::len(value: array<anytype>) -> int64

Returns the number of elements of a given value.

This function works with the `str`, `bytes` and `array` types:

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) -> boolstd::contains(haystack: range<anypoint>, needle: range<anypoint>) -> std::boolstd::contains(haystack: range<anypoint>, needle: anypoint) -> std::boolstd::contains(haystack: multirange<anypoint>, needle: multirange<anypoint>) -> std::boolstd::contains(haystack: multirange<anypoint>, needle: range<anypoint>) -> std::boolstd::contains(haystack: multirange<anypoint>, needle: anypoint) -> std::bool

Returns true if the given sub-value exists within the given value.

When haystack is a `str` or a `bytes` value, this function will return `true` if it contains needle as a subsequence within it or `false` otherwise:

Copy
`db> `
`select contains('qwerty', 'we');`
```{true}
```
Copy
`db> `
`select contains(b'qwerty', b'42');`
`{false}`

When haystack is an `array`, the function will return `true` if the array contains the element specified as needle or `false` otherwise:

Copy
`db> `
`select contains([2, 5, 7, 2, 100], 2);`
`{true}`

When haystack is a range, the function will return `true` if it contains either the specified sub-range or element. The function will return `false` otherwise.

Copy
`db> `
`select contains(range(1, 10), range(2, 5));`
```{true}
```
Copy
`db> `
`select contains(range(1, 10), range(2, 15));`
```{false}
```
Copy
`db> `
`select contains(range(1, 10), 2);`
```{true}
```
Copy
`db> `
`select contains(range(1, 10), 10);`
`{false}`

When haystack is a multirange, the function will return `true` if it contains either the specified multirange, sub-range or element. The function will return `false` otherwise.

Copy
```db>
...
...
...
...
...
...
... ```
```select contains(
multirange([
range(1, 4), range(7),
]),
multirange([
range(1, 2), range(8, 10),
]),
);```
```{true}
```
Copy
```db>
...
...
...
...
... ```
```select contains(
multirange([
range(1, 4), range(8, 10),
]),
range(8),
);```
```{false}
```
Copy
```db>
...
...
...
...
... ```
```select contains(
multirange([
range(1, 4), range(8, 10),
]),
3,
);```
`{true}`

When haystack is JSON, the function will return `true` if the json data contains the element specified as needle or `false` otherwise:

Copy
```db>
...
...
...
...
...
...
... ```
```with haystack := to_json('{
"city": "Baerlon",
"city": "Caemlyn"
}'),
needle := to_json('{
"city": "Caemlyn"
}'),
select contains(haystack, needle);```
`{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

Returns the index of a given sub-value in a given value.

When haystack is a `str` or a `bytes` value, the function will return the index of the first occurrence of needle in it.

When haystack is an `array`, this will return the index of the the first occurrence of the element passed as needle. 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}`