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.



More posts like this

Edgedb Computed Links

2023-04-12 | #edgedb #edgedb-links

Computed Links is a structure used to define relationships between two objects. These links are created by using a defined query or function to calculate the relationship between associated objects. Computed Links is a structure used to define relationships between two objects. These connections are created by using a defined query or function to calculate the relationship between the associated objects. This structure is very useful for ensuring consistency of the data held in the database.

Continue reading 


Edgedb Exclusive Constraint

2023-04-12 | #edgedb #edgedb-constraints

The term exclusive constraint in EdgeDB refers to a type of constraint that ensures a specific property is unique or within a certain range. For example, you can create an exclusive constraint in a User object that ensures the email property is unique, thus ensuring that each user is only saved once. In the following example, we are defining an exclusive constraint that ensures uniqueness in the email property: type User { required property id -> uuid; required property name -> str; exclusive constraint unique_email on (.

Continue reading 


Edgedb Constraints

2023-04-11 | #edgedb #edgedb-constraints

Edgedb is a relational database management system (RDBMS) that provides various constraint mechanisms to securely store and manage your data while preserving the integrity of the data recorded in your database. Constraints are a set of rules used to maintain the integrity of the data stored in your database. There are five different types of constraint: 1. Primary Key Constraints: Primary key constraints ensure that each row is uniquely identified. This constraint specifies that there can only be one primary key column in a table, and each value in this column can only be used once.

Continue reading 