See Section 8.17 for an overview of range types.
Table 9.56 shows the specialized operators available for range types. Table 9.57 shows the specialized operators available for multirange types. In addition to those, the usual comparison operators shown in Table 9.1 are available for range and multirange types. The comparison operators order first by the range lower bounds, and only if those are equal do they compare the upper bounds. The multirange operators compare each range until one is unequal. This does not usually result in a useful overall ordering, but the operators are provided to allow unique indexes to be constructed on ranges.
Table 9.56. Range Operators
Operator Description Example(s) |
---|
anyrange Does the first range contain the second?
|
anyrange Does the range contain the element?
|
anyrange Is the first range contained by the second?
|
anyelement Is the element contained in the range?
|
anyrange Do the ranges overlap, that is, have any elements in common?
|
anyrange Is the first range strictly left of the second?
|
anyrange Is the first range strictly right of the second?
|
anyrange Does the first range not extend to the right of the second?
|
anyrange Does the first range not extend to the left of the second?
|
anyrange Are the ranges adjacent?
|
anyrange
Computes the union of the ranges. The ranges must overlap or be
adjacent, so that the union is a single range (but
see
|
anyrange Computes the intersection of the ranges.
|
anyrange Computes the difference of the ranges. The second range must not be contained in the first in such a way that the difference would not be a single range.
|
Table 9.57. Multirange Operators
Operator Description Example(s) |
---|
anymultirange Does the first multirange contain the second?
|
anymultirange Does the multirange contain the range?
|
anymultirange Does the multirange contain the element?
|
anyrange Does the range contain the multirange?
|
anymultirange Is the first multirange contained by the second?
|
anymultirange Is the multirange contained by the range?
|
anyrange Is the range contained by the multirange?
|
anyelement Is the element contained by the multirange?
|
anymultirange Do the multiranges overlap, that is, have any elements in common?
|
anymultirange Does the multirange overlap the range?
|
anyrange Does the range overlap the multirange?
|
anymultirange Is the first multirange strictly left of the second?
|
anymultirange Is the multirange strictly left of the range?
|
anyrange Is the range strictly left of the multirange?
|
anymultirange Is the first multirange strictly right of the second?
|
anymultirange Is the multirange strictly right of the range?
|
anyrange Is the range strictly right of the multirange?
|
anymultirange Does the first multirange not extend to the right of the second?
|
anymultirange Does the multirange not extend to the right of the range?
|
anyrange Does the range not extend to the right of the multirange?
|
anymultirange Does the first multirange not extend to the left of the second?
|
anymultirange Does the multirange not extend to the left of the range?
|
anyrange Does the range not extend to the left of the multirange?
|
anymultirange Are the multiranges adjacent?
|
anymultirange Is the multirange adjacent to the range?
|
anyrange Is the range adjacent to the multirange?
|
anymultirange Computes the union of the multiranges. The multiranges need not overlap or be adjacent.
|
anymultirange Computes the intersection of the multiranges.
|
anymultirange Computes the difference of the multiranges.
|
The left-of/right-of/adjacent operators always return false when an empty range or multirange is involved; that is, an empty range is not considered to be either before or after any other range.
Elsewhere empty ranges and multiranges are treated as the additive identity: anything unioned with an empty value is itself. Anything minus an empty value is itself. An empty multirange has exactly the same points as an empty range. Every range contains the empty range. Every multirange contains as many empty ranges as you like.
The range 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. There are separate operators for union and difference that take multirange parameters and return a multirange, and they do not fail even if their arguments are disjoint. So if you need a union or difference operation for ranges that may be disjoint, you can avoid errors by first casting your ranges to multiranges.
Table 9.58 shows the functions available for use with range types. Table 9.59 shows the functions available for use with multirange types.
Table 9.58. Range Functions
Table 9.59. Multirange Functions
The lower_inc
, upper_inc
,
lower_inf
, and upper_inf
functions all return false for an empty range or multirange.