Generic Functions and Operators​
|
Compares two values for equality. | |
|
Compares two values for inequality. | |
|
Compares two (potentially empty) values for equality. | |
|
Compares two (potentially empty) values for inequality. | |
|
Less than operator. | |
|
Greater than operator. | |
|
Less or equal operator. | |
|
Greater or equal operator. | |
|
Returns the number of elements of a given value. | |
|
Returns true if the given sub-value exists within the given value. | |
|
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.
Compares two values for equality.
db>
select 3 = 3.0;{true}db>
select 3 = 3.14;{false}db>
select [1, 2] = [1, 2];{true}db>
select (1, 2) = (x := 1, y := 2);{true}db>
select (x := 1, y := 2) = (a := 1, b := 2);{true}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.
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.
Compares two values for inequality.
db>
select 3 != 3.0;{false}db>
select 3 != 3.14;{true}db>
select [1, 2] != [2, 1];{false}db>
select (1, 2) != (x := 1, y := 2);{false}db>
select (x := 1, y := 2) != (a := 1, b := 2);{false}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.
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.
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.
db>
select {1} ?= {1.0};{true}db>
select {1} ?= <int64>{};{false}db>
select <int64>{} ?= <int64>{};{true}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.
db>
select {2} ?!= {2};{false}db>
select {1} ?!= <int64>{};{true}db>
select <bool>{} ?!= <bool>{};{false}Less than operator.
The operator returns 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}db>
select 'hello' < 'world';{true}db>
select (1, 'hello') < (1, 'world');{true}When either operand in a comparison is an empty set, the result will
not be a bool but instead an empty set.
db>
select 1 < <int16>{};{}If one of the operands in a comparison could be an empty set, you may
want to coalesce the result of the comparison with false to ensure
your result is boolean.
db>
select (1 < <int16>{}) ?? false;{false}Greater than operator.
The operator returns 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}db>
select 'hello' > 'world';{false}db>
select (1, 'hello') > (1, 'world');{false}When either operand in a comparison is an empty set, the result will
not be a bool but instead an empty set.
db>
select 1 > <int16>{};{}If one of the operands in a comparison could be an empty set, you may
want to coalesce the result of the comparison with false to ensure
your result is boolean.
db>
select (1 > <int16>{}) ?? false;{false}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:
db>
select 1 <= 2;{true}db>
select 2 <= 2;{true}db>
select 3 <= 2;{false}db>
select 'hello' <= 'world';{true}db>
select (1, 'hello') <= (1, 'world');{true}When either operand in a comparison is an empty set, the result will
not be a bool but instead an empty set.
db>
select 1 <= <int16>{};{}If one of the operands in a comparison could be an empty set, you may
want to coalesce the result of the comparison with false to ensure
your result is boolean.
db>
select (1 <= <int16>{}) ?? false;{false}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:
db>
select 1 >= 2;{false}db>
select 2 >= 2;{true}db>
select 3 >= 2;{true}db>
select 'hello' >= 'world';{false}db>
select (1, 'hello') >= (1, 'world');{false}When either operand in a comparison is an empty set, the result will
not be a bool but instead an empty set.
db>
select 1 >= <int16>{};{}If one of the operands in a comparison could be an empty set, you may
want to coalesce the result of the comparison with false to ensure
your result is boolean.
db>
select (1 >= <int16>{}) ?? false;{false}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:
db>
select contains('qwerty', 'we');{true}
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:
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.
db>
select contains(range(1, 10), range(2, 5));{true}
db>
select contains(range(1, 10), range(2, 15));{false}
db>
select contains(range(1, 10), 2);{true}
db>
select contains(range(1, 10), 10);{false}When haystack is a multirange (added in 4.0), the function
will return true if it contains either the specified multirange,
sub-range or element. The function will return false otherwise.
db> ... ... ... ... ... ... ...
select contains(
multirange([
range(1, 4), range(7),
]),
multirange([
range(1, 2), range(8, 10),
]),
);{true}
db> ... ... ... ... ...
select contains(
multirange([
range(1, 4), range(8, 10),
]),
range(8),
);{false}
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:
db> ... ... ... ... ... ... ...
with haystack := to_json('{
"city": "Baerlon",
"city": "Caemlyn"
}'),
needle := to_json('{
"city": "Caemlyn"
}'),
select contains(haystack, needle);{true}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.
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}