Range
A Range represents a SurrealDB range value with a begin and end bound. Each bound can be inclusive or exclusive. Range is a Python dataclass.
Import
from surrealdb import Range
from surrealdb.data.types.range import BoundIncluded, BoundExcluded
Bound Classes
The Bound base class has two subclasses that define whether a boundary value is included or excluded.
BoundIncluded
An inclusive bound. The boundary value is part of the range.
| Property | Type | Description |
|---|
value | Value | The boundary value. |
BoundExcluded
An exclusive bound. The boundary value is not part of the range.
| Property | Type | Description |
|---|
value | Value | The boundary value. |
Range Dataclass
Fields
| Field | Type | Description |
|---|
begin | Bound | The start bound of the range. |
end | Bound | The end bound of the range. |
Constructor
Syntax
Range(begin, end)
| Parameter | Type | Description |
|---|
begin required | Bound | The start bound (inclusive or exclusive). |
end required | Bound | The end bound (inclusive or exclusive). |
Examples
Inclusive range 1 to 10
from surrealdb import Range
from surrealdb.data.types.range import BoundIncluded
r = Range(
begin=BoundIncluded(1),
end=BoundIncluded(10),
)
Half-open range 1 to 10
from surrealdb.data.types.range import BoundIncluded, BoundExcluded
r = Range(
begin=BoundIncluded(1),
end=BoundExcluded(10),
)
Using with queries
from surrealdb import Surreal, Range
from surrealdb.data.types.range import BoundIncluded
db = Surreal("ws://localhost:8000")
db.connect()
db.use("my_ns", "my_db")
db.signin({"username": "root", "password": "root"})
result = db.query(
"SELECT * FROM events WHERE year IN $range",
{"range": Range(BoundIncluded(2020), BoundIncluded(2025))},
)
See Also