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. (The bounds of their ranges may be quoted as above however.)Ĩ.17.6. Constructing Ranges and MultirangesĮach range type has a constructor function with the same name as the range type. This is intended to be reminiscent of array syntax, although multiranges are much simpler: they have just one dimension and there is no need to quote their contents. Whitespace is permitted around the brackets and commas. The input for a multirange is curly brackets ( ) containing zero or more valid ranges, separated by commas. includes no points (and will be normalized to 'empty') does not include either 3 or 7, but includes all points in between includes 3, does not include 7, and does include all points in between See Section 8.16.6 for additional commentary. These rules are very similar to those for writing field values in composite-type literals. (Depending on the element type, it might or might not be significant.) 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: 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]. Most range operators also work on multiranges, and they have a few functions of their own. A multirange is an ordered list of non-contiguous, non-empty, non-null ranges. The use of time and date ranges for scheduling purposes is the clearest example but price ranges, measurement ranges from an instrument, and so forth can also be useful.Įvery range type has a corresponding multirange type. Range types are useful because they represent many element values in a single range value, and because concepts such as overlapping ranges can be expressed clearly. The subtype must have a total order so that it is well-defined whether element values are within, before, or after a range of values. In this case the data type is tsrange (short for “ timestamp range”), and timestamp is the subtype. For instance, ranges of timestamp might be used to represent the ranges of time that a meeting room is reserved. Range types are data types representing a range of values of some element type (called the range's subtype). Constructing Ranges and Multiranges 8.17.7. Built-in Range and Multirange Types 8.17.2.
0 Comments
Leave a Reply. |