---
title: Range Term
description: Filters over Postgres range types
canonical: https://docs.paradedb.com/documentation/query-builder/term/range-term
---

`range_term` is the equivalent of Postgres' operators over [range types](https://www.postgresql.org/docs/current/rangetypes.html).
It supports operations like range containment, overlap, and intersection.

## Term Within

In this example, `weight_range` is an `int4range` type.
The following query finds all rows where `weight_range` contains `1`:

<CodeGroup>
```sql SQL
SELECT id, weight_range FROM mock_items
WHERE weight_range @@@ pdb.range_term(1);
```

```python Django
from paradedb import ParadeDB, RangeTerm

MockItem.objects.filter(
    weight_range=ParadeDB(RangeTerm(1))
).values('id', 'weight_range')
```

```python SQLAlchemy
from sqlalchemy import select
from sqlalchemy.orm import Session
from paradedb.sqlalchemy import search

stmt = (
    select(MockItem.id, MockItem.weight_range)
    .where(search.range_term(MockItem.weight_range, 1))
)

with Session(engine) as session:
    session.execute(stmt).all()
```

```ruby Rails
MockItem.search(:weight_range)
        .range_term(1)
        .select(:id, :weight_range)
```

</CodeGroup>

## Range Intersects

The following query finds all ranges that share at least one common
point with the query range:

<CodeGroup>
```sql SQL
SELECT id, weight_range FROM mock_items
WHERE weight_range @@@ pdb.range_term('(10, 12]'::int4range, 'Intersects');
```

```python Django
from paradedb import ParadeDB, RangeTerm

MockItem.objects.filter(
    weight_range=ParadeDB(RangeTerm('(10, 12]', relation='Intersects', range_type='int4range'))
).values('id', 'weight_range')
```

```python SQLAlchemy
from sqlalchemy import select
from sqlalchemy.orm import Session
from paradedb.sqlalchemy import search

stmt = (
    select(MockItem.id, MockItem.weight_range)
    .where(
        search.range_term(
            MockItem.weight_range,
            "(10, 12]",
            relation="Intersects",
            range_type="int4range",
        )
    )
)

with Session(engine) as session:
    session.execute(stmt).all()
```

```ruby Rails
MockItem.search(:weight_range)
        .range_term("(10, 12]", relation: "Intersects", range_type: "int4range")
        .select(:id, :weight_range)
```

</CodeGroup>

## Range Contains

The following query finds all ranges that are contained by the query range:

<CodeGroup>
```sql SQL
SELECT id, weight_range FROM mock_items
WHERE weight_range @@@ pdb.range_term('(3, 9]'::int4range, 'Contains');
```

```python Django
from paradedb import ParadeDB, RangeTerm

MockItem.objects.filter(
    weight_range=ParadeDB(RangeTerm('(3, 9]', relation='Contains', range_type='int4range'))
).values('id', 'weight_range')
```

```python SQLAlchemy
from sqlalchemy import select
from sqlalchemy.orm import Session
from paradedb.sqlalchemy import search

stmt = (
    select(MockItem.id, MockItem.weight_range)
    .where(
        search.range_term(
            MockItem.weight_range,
            "(3, 9]",
            relation="Contains",
            range_type="int4range",
        )
    )
)

with Session(engine) as session:
    session.execute(stmt).all()
```

```ruby Rails
MockItem.search(:weight_range)
        .range_term("(3, 9]", relation: "Contains", range_type: "int4range")
        .select(:id, :weight_range)
```

</CodeGroup>

## Range Within

The following query finds all ranges that contain the query range:

<CodeGroup>
```sql SQL
SELECT id, weight_range FROM mock_items
WHERE weight_range @@@ pdb.range_term('(2, 11]'::int4range, 'Within');
```

```python Django
from paradedb import ParadeDB, RangeTerm

MockItem.objects.filter(
    weight_range=ParadeDB(RangeTerm('(2, 11]', relation='Within', range_type='int4range'))
).values('id', 'weight_range')
```

```python SQLAlchemy
from sqlalchemy import select
from sqlalchemy.orm import Session
from paradedb.sqlalchemy import search

stmt = (
    select(MockItem.id, MockItem.weight_range)
    .where(
        search.range_term(
            MockItem.weight_range,
            "(2, 11]",
            relation="Within",
            range_type="int4range",
        )
    )
)

with Session(engine) as session:
    session.execute(stmt).all()
```

```ruby Rails
MockItem.search(:weight_range)
        .range_term("(2, 11]", relation: "Within", range_type: "int4range")
        .select(:id, :weight_range)
```

</CodeGroup>
