Edgedb Range
[tr] Türkçe Oku 2023-04-11
Edgedb offers a data type called range
, which represents a range or numerical interval. The range data type is very useful for mathematical or numerical operations, and is commonly used in database queries.
The range data type is expressed as range<T>
, where T represents the data type used in the range. The range data type represents an interval between two values and can be defined for a specific data type. For example, the range<int64>
data type represents a numerical interval between two int64
numbers.
The range data type can define the interval between two values as either open or closed. An open interval does not include the boundary values, while a closed interval includes them. For example, the expression [1, 10)
represents the range of numbers that includes 1 but not 10, while the expression [1, 10]
represents all numbers between 1 and 10 inclusive.
The range data type can also be defined using the ..
or ...
operators. The ..
operator represents a closed range, while the ...
operator represents an open range. For example, the expression 1..10 represents all numbers between 1 and 10 inclusive.
The range data type can be used for many mathematical or numerical operations. The range data type is quite useful for sorting and filtering operations and is commonly used in database queries.
The operations that can be performed with the range data type include:
- The
in
operator: Used to check if a value is inside or outside a range. - The
contains
function: Used to check if a range contains a value. - The
overlaps
function: Used to check if two ranges overlap. - The
adjacent
function: Used to check if two ranges have adjacent boundaries. - The
is_empty
function: Used to check if a range is empty. - The
union
function: Returns the union of two ranges. - The
intersection
function: Returns the intersection of two ranges. - The
difference
function: Returns the difference between two ranges.
SELECT range(1, 10) # 1..10
SELECT range(1, 10, step := 2) # 1, 3, 5, 7, 9
SELECT 5 in range(1, 10) # true
SELECT contains(range(1, 10), 5) # true
SELECT overlaps(range(1, 5), range(3, 7)) # true
SELECT adjacent(range(1, 5), range(6, 10)) # true
SELECT is_empty(range(5, 5)) # true
SELECT range(1, 5) + range(6, 10) # 1..10
SELECT range(1, 10) - range(5, 8) # 1..4, 9..10
SELECT range(1, 10).union(range(5, 8)) # 1..10
SELECT range(1, 10).intersection(range(5, 8)) # 5..8
SELECT range(1, 10).difference(range(5, 8)) # 1..4, 9..10
The range data type can also be used to select a specific portion of an array or query. For example, the expression
my_array[1..3]
returns a sub-array containing the elements between the 1st and 3rd indexes of my_array
.
Edgedb provides an advanced tool for performing mathematical or numerical operations in database queries thanks to the range data type. The range data type is very useful for representing intervals or numerical ranges, and it simplifies database queries. Edgedb’s rich data types help developers to perform database operations more efficiently and effectively.