isempty
Range types (including `isempty()`) introduced in PostgreSQL 9.2.→ booleanReturns true if the range is empty (contains no points).
Signature
isempty ( anyrange ) → booleanParameters
| Parameter | Type | Description |
|---|---|---|
| range | anyrange | Range to test |
Examples
SELECT isempty('empty'::int4range);trueSELECT isempty('[1,1)'::int4range);trueSELECT isempty('[1,2)'::int4range);falseSELECT a.id, b.id FROM slots a JOIN slots b ON NOT isempty(a.period * b.period) WHERE a.id < b.id;All pairs of overlapping time slotsCalling `isempty(r1 * r2)` computes a full intersection just to test overlap. The `&&` operator tests overlap directly without materialising the intersection result and is index-eligible with a GiST index. Use `&&` in WHERE clauses; reserve `isempty` for checking the result of an intersection you already needed.
✓ Instead: SELECT * FROM bookings WHERE room_id = $1 AND period && $new_period::daterange;
Range intersection `*` can return an empty range when there's no overlap. Use `isempty(r1 * r2)` to check if two ranges share any points.
SELECT isempty('[1,5)'::int4range * '[6,10)'::int4range) AS no_overlap;true (ranges don't overlap)