--- title: Range Term --- ## Basic Usage `range_term` filters over `int4range`, `int8range`, `numrange`, `tsrange`, and `tstzrange` [range fields](/documentation/indexing/create_index#range-fields). The following query finds all ranges that contain a specific value: ```sql Function Syntax SELECT id, weight_range FROM mock_items WHERE id @@@ paradedb.range_term('weight_range', 1); ``` ```sql JSON Syntax SELECT id, weight_range FROM mock_items WHERE id @@@ '{ "range_term": { "field": "weight_range", "value": 1 } }'::jsonb; ``` `range_term` can be used with `boolean` queries to "push down" the range filter into the full text search query. ```sql Function Syntax 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') ] ); ``` ```sql JSON Syntax SELECT id, description, category, weight_range FROM mock_items WHERE id @@@ '{ "boolean": { "must": [ { "range_term": { "field": "weight_range", "value": 1 } }, { "term": { "field": "category", "value": "footwear" } } ] } }'::jsonb; ``` ## Range Comparison In addition to individual terms, `range_term` can also compare a [Postgres range](https://www.postgresql.org/docs/current/rangetypes.html) 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: ```sql Function Syntax SELECT id, weight_range FROM mock_items WHERE id @@@ paradedb.range_term('weight_range', '(10, 12]'::int4range, 'Intersects'); ``` ```sql JSON Syntax SELECT id, weight_range FROM mock_items WHERE id @@@ '{ "range_intersects": { "field": "weight_range", "lower_bound": {"excluded": 10}, "upper_bound": {"included": 12} } }'::jsonb; ``` ### Contains The following query finds all ranges that are contained by the query range: ```sql Function Syntax SELECT id, weight_range FROM mock_items WHERE id @@@ paradedb.range_term('weight_range', '(3, 9]'::int4range, 'Contains'); ``` ```sql JSON Syntax SELECT id, weight_range FROM mock_items WHERE id @@@ '{ "range_contains": { "field": "weight_range", "lower_bound": {"excluded": 3}, "upper_bound": {"included": 9} } }'::jsonb; ``` ### Within The following query finds all ranges that contain the query range: ```sql Function Syntax SELECT id, weight_range FROM mock_items WHERE id @@@ paradedb.range_term('weight_range', '(2, 11]'::int4range, 'Within'); ``` ```sql JSON Syntax SELECT id, weight_range FROM mock_items WHERE id @@@ '{ "range_within": { "field": "weight_range", "lower_bound": {"excluded": 2}, "upper_bound": {"included": 11} } }'::jsonb; ```