Buy Me A Coffee

Edgedb Range

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 İlişkiler

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

Edgedb’de iki tablo arasında ilişki kurmak için link anahtar kelimesi kullanılır. Linkler, bir objenin başka bir objeyle ilişkilendirilmesine izin verir. Örneğin, bir User tablosu ve bir Article tablosu varsa, Article tablosundaki her bir Article, bir Userya atfedilebilir. Bu durumda, User ve Article tabloları arasında bir ilişki kurabiliriz. İlk olarak, User tablosunda bir id özelliği tanımlarız. Bu özellik, kullanıcının benzersiz bir kimliğini temsil eder. type User { required property id -> uuid; property name -> str; } Ardından, Article tablosunda bir author özelliği tanımlarız.

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 