Home Explore Blog CI



postgresql

3rd chunk of `doc/src/sgml/rangetypes.sgml`
e14f285a1afa9f53176750a3161bbf8dfb2c71189d5ac5b40000000100000fa4
 <para>
   The functions <literal>lower_inf</literal>
   and <literal>upper_inf</literal> test for infinite lower
   and upper bounds of a range, respectively.
  </para>
 </sect2>

 <sect2 id="rangetypes-io">
  <title>Range Input/Output</title>

  <para>
   The input for a range value must follow one of the following patterns:
<synopsis>
(<replaceable>lower-bound</replaceable>,<replaceable>upper-bound</replaceable>)
(<replaceable>lower-bound</replaceable>,<replaceable>upper-bound</replaceable>]
[<replaceable>lower-bound</replaceable>,<replaceable>upper-bound</replaceable>)
[<replaceable>lower-bound</replaceable>,<replaceable>upper-bound</replaceable>]
empty
</synopsis>
   The parentheses or brackets indicate whether the lower and upper bounds
   are exclusive or inclusive, as described previously.
   Notice that the final pattern is <literal>empty</literal>, which
   represents an empty range (a range that contains no points).
  </para>

  <para>
   The <replaceable>lower-bound</replaceable> may be either a string
   that is valid input for the subtype, or empty to indicate no
   lower bound.  Likewise, <replaceable>upper-bound</replaceable> may be
   either a string that is valid input for the subtype, or empty to
   indicate no upper bound.
  </para>

  <para>
   Each bound value can be quoted using <literal>"</literal> (double quote)
   characters.  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.  To put a double
   quote or backslash in a quoted bound value, precede it with a
   backslash. (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.  Also, to write a bound
   value that is an empty string, write <literal>""</literal>, since writing
   nothing means an infinite bound.
  </para>

  <para>
   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.  (Depending on the element type, it might or might not be
   significant.)
  </para>

  <note>
   <para>
    These rules are very similar to those for writing field values in
    composite-type literals.  See <xref linkend="rowtypes-io-syntax"/> for
    additional commentary.
   </para>
  </note>

  <para>
  Examples:
<programlisting>
-- includes 3, does not include 7, and does include all points in between
SELECT '[3,7)'::int4range;

-- does not include either 3 or 7, but includes all points in between
SELECT '(3,7)'::int4range;

-- includes only the single point 4
SELECT '[4,4]'::int4range;

-- includes no points (and will be normalized to 'empty')
SELECT '[4,4)'::int4range;
</programlisting>
  </para>

  <para>
   The input for a multirange is curly brackets (<literal>{</literal> and
   <literal>}</literal>) containing zero or more valid ranges,
   separated by commas. Whitespace is permitted around the brackets and
   commas. 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. (The bounds of their ranges may be
   quoted as above however.)
  </para>

  <para>
  Examples:
<programlisting>
SELECT '{}'::int4multirange;
SELECT '{[3,7)}'::int4multirange;
SELECT '{[3,7), [8,9)}'::int4multirange;
</programlisting>
  </para>

 </sect2>

 <sect2 id="rangetypes-construct">
  <title>Constructing Ranges and Multiranges</title>

  <para>
   Each range type has a constructor function with the same name as the range
   type.  Using the constructor function is frequently more convenient than
   writing a range literal constant, since it avoids

Title: Range and Multirange Input/Output and Construction
Summary
This section describes the detailed input formats for range values, including the use of parentheses and brackets to indicate inclusivity/exclusivity, and the use of 'empty' to represent an empty range. It explains how to represent lower and upper bounds, including the use of quoting to handle special characters. It provides examples of valid range inputs. It also covers the input format for multiranges, using curly brackets to enclose a comma-separated list of ranges. Finally, it briefly mentions the existence of constructor functions for creating range types, which can be more convenient than writing range literals.