Skip to content

RANGE

CREATE TABLE range_table (
id serial PRIMARY KEY,
value_range int4range
);
INSERT INTO range_table(value_range) VALUES
('[1,5]'),('[10,15]'),('[20,25]');
SELECT *
FROM range_table
WHERE value_range @> 11;
id | value_range
----|-------------
2 | [10,15]
(1 row)

In the above example, a range type int4range is created for storing integer values range in range_table. A few ranges are inserted into the table. The SELECT query with the WHERE condition value_range @> 11 shows the rows where the range includes the number 11. In this case, only the range ‘[10,15]’ includes the number 11, so it returns that row only.