Basic Usage
range_term
filters over int4range
, int8range
, numrange
, tsrange
, and tstzrange
range fields.
The following query finds all ranges that contain a specific value:
SELECT id, weight_range FROM mock_items
WHERE id @@@ paradedb.range_term('weight_range', 1);
range_term
can be used with boolean
queries to “push down” the range filter into the full text search query.
SELECT id, description, category, weight_range FROM mock_items
WHERE id @@@ paradedb.boolean(
must => ARRAY[
paradedb.range_term('weight_range', 1),
paradedb.term('category', 'footwear')
]
);
Range Comparison
In addition to individual terms, range_term
can also compare a Postgres range against the
range field.
Intersects
The following query finds all ranges that share at least one common
point with the query range:
Based on the SearchQueryInput enum showing RangeIntersects
as an option, here’s how we would write it:
SELECT id, weight_range FROM mock_items
WHERE id @@@ paradedb.range_term('weight_range', '(10, 12]'::int4range, 'Intersects');
Contains
The following query finds all ranges that are contained by the query range:
SELECT id, weight_range FROM mock_items
WHERE id @@@ paradedb.range_term('weight_range', '(3, 9]'::int4range, 'Contains');
Within
The following query finds all ranges that contain the query range:
SELECT id, weight_range FROM mock_items
WHERE id @@@ paradedb.range_term('weight_range', '(2, 11]'::int4range, 'Within');
Responses are generated using AI and may contain mistakes.