Range types

int4range and int4multirange — constructors, casts, containment, overlap.

Version
Latest
v0.1.0 · latest 1 min read
On this page
  1. Supported
  2. Related
✓

Supported. Range types registered with PostgreSQL OIDs; constructor functions for int4range and int4multirange.

Supported#

sqlsource
SELECT int4range(1, 10);                              -- [1,10)
SELECT int4multirange(int4range(1,3), int4range(5,7)); -- union of ranges
SELECT '[1,10)'::int4range, '[1,10]'::int4range;
SELECT '{[1,3),[5,7)}'::int4multirange;
SELECT 5 <@ int4range(1,10);                          -- contained
SELECT int4range(1,10) @> 5;                          -- contains
SELECT int4range(1,5) && int4range(4,10);             -- overlap → true
SELECT int4range(1,5) && int4range(5,10);             -- adjacent → false
SELECT 2 <@ '{[1,3),[5,7)}'::int4multirange;
SELECT 4 <@ '{[1,3),[5,7)}'::int4multirange;          -- gap → false

int4range(lower, upper) builds [lower, upper) (lower_inclusive: true, upper_inclusive: false); bounds must be integers. int4multirange(r, …) unions one or more int4range values.

Types · Scalar catalog · Compatibility

Was this page helpful?