PostgreSQL
9.19. Range Functions and Operators
See Section 8.17 for an overview of range types.
Table 9.50 shows the operators available for range types.
Table 9.50. Range Operators
Operator | Description | Example | Result |
---|---|---|---|
|
equal |
|
|
|
not equal |
|
|
|
less than |
|
|
|
greater than |
|
|
|
less than or equal |
|
|
|
greater than or equal |
|
|
|
contains range |
|
|
|
contains element |
|
|
|
range is contained by |
|
|
|
element is contained by |
|
|
|
overlap (have points in common) |
|
|
|
strictly left of |
|
|
|
strictly right of |
|
|
|
does not extend to the right of |
|
|
|
does not extend to the left of |
|
|
`+- |
-+` |
is adjacent to |
`+numrange(1.1,2.2) - |
- numrange(2.2,3.3)+` |
|
|
union |
|
|
|
intersection |
|
|
|
difference |
+
The simple comparison operators <
, >
, <=
, and >=
compare the lower bounds first, and only if those are equal, compare the upper bounds. These comparisons are not usually very useful for ranges, but are provided to allow B-tree indexes to be constructed on ranges.
The left-of/right-of/adjacent operators always return false when an empty range is involved; that is, an empty range is not considered to be either before or after any other range.
The union and difference operators will fail if the resulting range would need to contain two disjoint sub-ranges, as such a range cannot be represented.
Table 9.51 shows the functions available for use with range types.
Table 9.51. Range Functions
Function | Return Type | Description | Example | Result |
---|---|---|---|---|
|
range’s element type |
lower bound of range |
|
|
|
range’s element type |
upper bound of range |
|
|
|
|
is the range empty? |
|
|
|
|
is the lower bound inclusive? |
|
|
|
|
is the upper bound inclusive? |
|
|
|
|
is the lower bound infinite? |
|
|
|
|
is the upper bound infinite? |
|
|
|
|
the smallest range which includes both of the given ranges |
|
|
+
The lower
and upper
functions return null if the range is empty or the requested bound is infinite. The lower_inc
, upper_inc
, lower_inf
, and upper_inf
functions all return false for an empty range.
Prev | Up | Next |
---|---|---|
9.18. Array Functions and Operators |
9.20. Aggregate Functions |
Copyright © 1996-2023 The PostgreSQL Global Development Group