![]() The canonicalization function is charged with converting equivalent values of the range type to have identical representations, in particular consistently inclusive or exclusive bounds. For example, in an integer range type and (3,9) denote the same set of values but this would not be so for a range over numeric.Ī discrete range type should have a canonicalization function that is aware of the desired step size for the element type. Knowing that, it is possible to convert between inclusive and exclusive representations of a range's bounds, by choosing the next or previous element value instead of the one originally given. (Even though timestamp has limited precision, and so could theoretically be treated as discrete, it's better to consider it continuous since the step size is normally not of interest.)Īnother way to think about a discrete range type is that there is a clear idea of a "next" or "previous" value for each element value. For example, a range over the numeric type is continuous, as is a range over timestamp. This contrasts with continuous ranges, where it's always (or almost always) possible to identify other element values between two given values. In these types two elements can be said to be adjacent, when there are no valid values between them. Using NULL for either bound causes the range to be unbounded on that side.Ī discrete range is one whose element type has a well-defined "step", such as integer or date. canonical form, since int8range is a discrete range type (see below). Although '(]' is specified here, on display the value will be converted to If the third argument is omitted, '[)' is assumed. For example: - The full form is: lower bound, upper bound, and text argument indicating The third argument must be one of the strings " ()", " (]", " ". ![]() The two-argument form constructs a range in standard form (lower bound inclusive, upper bound exclusive), while the three-argument form constructs a range with bounds of the form specified by the third argument. The constructor function accepts two or three arguments. Using the constructor function is frequently more convenient than writing a range literal constant, since it avoids the need for extra quoting of the bound values. (Depending on the element type, it might or might not be significant.)Įach range type has a constructor function with the same name as the range type. Whitespace is allowed before and after the range value, but any whitespace between the parentheses or brackets is taken as part of the lower or upper bound value. Also, to write a bound value that is an empty string, write "", since writing nothing means an infinite bound. (Also, a pair of double quotes within a double-quoted bound value is taken to represent a double quote character, analogously to the rules for single quotes in SQL literal strings.) Alternatively, you can avoid quoting and use backslash-escaping to protect all data characters that would otherwise be taken as range syntax. To put a double quote or backslash in a quoted bound value, precede it with a backslash. This is necessary if the bound value contains parentheses, brackets, commas, double quotes, or backslashes, since these characters would otherwise be taken as part of the range syntax. Likewise, upper-bound may be either a string that is valid input for the subtype, or empty to indicate no upper bound.Įach bound value can be quoted using " (double quote) characters. The lower-bound may be either a string that is valid input for the subtype, or empty to indicate no lower bound. Notice that the final pattern is empty, which represents an empty range (a range that contains no points). The parentheses or brackets indicate whether the lower and upper bounds are exclusive or inclusive, as described previously. The input for a range value must follow one of the following patterns: ( lower-bound, upper-bound) The functions lower_inf and upper_inf test for infinite lower and upper bounds of a range, respectively. For example, with timestamp ranges, include it, as does. ![]() You can think of these missing values as +/-infinity, but they are special range type values and are considered to be beyond any range element type's +/-infinity values.Įlement types that have the notion of "infinity" can use them as explicit bound values. Specifying a missing bound as inclusive is automatically converted to exclusive, e.g., is converted to (,). If both lower and upper bounds are omitted, all values of the element type are considered to be in the range. Likewise, if the upper bound of the range is omitted, then all values greater than the lower bound are included in the range. The lower bound of a range can be omitted, meaning that all values less than the upper bound are included in the range, e.g., (,3].
0 Comments
Leave a Reply. |