---
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);
```

```ts Drizzle
import { search } from "@paradedb/drizzle-paradedb";

await db
  .select({
    id: mockItems.id,
    weightRange: mockItems.weightRange,
  })
  .from(mockItems)
  .where(search.rangeTerm(mockItems.weightRange, 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)
```

```cs EF Core
await dbContext
    .MockItems.Where(item => EF.Functions.RangeTerm(item.WeightRange, 1))
    .Select(item => new { item.Id, item.WeightRange })
    .ToListAsync();
```

</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');
```

```ts Drizzle
import { search } from "@paradedb/drizzle-paradedb";

await db
  .select({
    id: mockItems.id,
    weightRange: mockItems.weightRange,
  })
  .from(mockItems)
  .where(search.rangeTerm(mockItems.weightRange, "(10, 12]", "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)
```

```cs EF Core
var range = new NpgsqlRange<int>(10, false, 12, true);

await dbContext
    .MockItems.Where(item =>
        EF.Functions.RangeTerm(item.WeightRange, range, RangeTermRelation.Intersects)
    )
    .Select(item => new { item.Id, item.WeightRange })
    .ToListAsync();
```

</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');
```

```ts Drizzle
import { search } from "@paradedb/drizzle-paradedb";

await db
  .select({
    id: mockItems.id,
    weightRange: mockItems.weightRange,
  })
  .from(mockItems)
  .where(search.rangeTerm(mockItems.weightRange, "(3, 9]", "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)
```

```cs EF Core
var range = new NpgsqlRange<int>(3, false, 9, true);

await dbContext
    .MockItems.Where(item =>
        EF.Functions.RangeTerm(item.WeightRange, range, RangeTermRelation.Contains)
    )
    .Select(item => new { item.Id, item.WeightRange })
    .ToListAsync();
```

</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');
```

```ts Drizzle
import { search } from "@paradedb/drizzle-paradedb";

await db
  .select({
    id: mockItems.id,
    weightRange: mockItems.weightRange,
  })
  .from(mockItems)
  .where(search.rangeTerm(mockItems.weightRange, "(2, 11]", "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)
```

```cs EF Core
var range = new NpgsqlRange<int>(2, false, 11, true);

await dbContext
    .MockItems.Where(item =>
        EF.Functions.RangeTerm(item.WeightRange, range, RangeTermRelation.Within)
    )
    .Select(item => new { item.Id, item.WeightRange })
    .ToListAsync();
```

</CodeGroup>
