Skip to content

Commit a1a233a

Browse files
committed
Further review of range-types patch.
Lots of documentation cleanup today, and still more type_sanity tests.
1 parent c1458cc commit a1a233a

File tree

12 files changed

+557
-251
lines changed

12 files changed

+557
-251
lines changed

doc/src/sgml/catalogs.sgml

+25-8
Original file line numberDiff line numberDiff line change
@@ -4607,7 +4607,9 @@
46074607
</indexterm>
46084608

46094609
<para>
4610-
The catalog <structname>pg_range</structname> stores information about range types.
4610+
The catalog <structname>pg_range</structname> stores information about
4611+
range types. This is in addition to the types' entries in
4612+
<link linkend="catalog-pg-type"><structname>pg_type</structname></link>.
46114613
</para>
46124614

46134615
<table>
@@ -4628,47 +4630,57 @@
46284630
<entry><structfield>rngtypid</structfield></entry>
46294631
<entry><type>oid</type></entry>
46304632
<entry><literal><link linkend="catalog-pg-type"><structname>pg_type</structname></link>.oid</literal></entry>
4631-
<entry>The type that is a range type</entry>
4633+
<entry>OID of the range type</entry>
46324634
</row>
46334635

46344636
<row>
46354637
<entry><structfield>rngsubtype</structfield></entry>
46364638
<entry><type>oid</type></entry>
46374639
<entry><literal><link linkend="catalog-pg-type"><structname>pg_type</structname></link>.oid</literal></entry>
4638-
<entry>Subtype of this range type, e.g. <type>integer</type> is the subtype of <type>int4range</type></entry>
4640+
<entry>OID of the element type (subtype) of this range type</entry>
46394641
</row>
46404642

46414643
<row>
46424644
<entry><structfield>rngcollation</structfield></entry>
46434645
<entry><type>oid</type></entry>
46444646
<entry><literal><link linkend="catalog-pg-collation"><structname>pg_collation</structname></link>.oid</literal></entry>
4645-
<entry>The collation used when comparing range boundaries</entry>
4647+
<entry>OID of the collation used for range comparisons, or 0 if none</entry>
46464648
</row>
46474649

46484650
<row>
46494651
<entry><structfield>rngsubopc</structfield></entry>
46504652
<entry><type>oid</type></entry>
46514653
<entry><literal><link linkend="catalog-pg-opclass"><structname>pg_opclass</structname></link>.oid</literal></entry>
4652-
<entry>The operator class used when comparing range boundaries</entry>
4654+
<entry>OID of the subtype's operator class used for range comparisons</entry>
46534655
</row>
46544656

46554657
<row>
46564658
<entry><structfield>rngcanonical</structfield></entry>
46574659
<entry><type>regproc</type></entry>
46584660
<entry><literal><link linkend="catalog-pg-proc"><structname>pg_proc</structname></link>.oid</literal></entry>
4659-
<entry>A function to convert a range into its canonical form</entry>
4661+
<entry>OID of the function to convert a range value into canonical form,
4662+
or 0 if none</entry>
46604663
</row>
46614664

46624665
<row>
46634666
<entry><structfield>rngsubdiff</structfield></entry>
46644667
<entry><type>regproc</type></entry>
46654668
<entry><literal><link linkend="catalog-pg-proc"><structname>pg_proc</structname></link>.oid</literal></entry>
4666-
<entry>A function to return the distance between two lower and upper bound, as a <type>double precision</type>. Used for GiST support</entry>
4669+
<entry>OID of the function to return the difference between two element
4670+
values as <type>double precision</type>, or 0 if none</entry>
46674671
</row>
46684672
</tbody>
46694673
</tgroup>
46704674
</table>
46714675

4676+
<para>
4677+
<structfield>rngsubopc</> (plus <structfield>rngcollation</>, if the
4678+
element type is collatable) determines the sort ordering used by the range
4679+
type. <structfield>rngcanonical</> is used when the element type is
4680+
discrete. <structfield>rngsubdiff</> is optional but should be supplied to
4681+
improve performance of GiST indexes on the range type.
4682+
</para>
4683+
46724684
</sect1>
46734685

46744686
<sect1 id="catalog-pg-rewrite">
@@ -6059,7 +6071,8 @@
60596071
<literal>c</literal> for a composite type (e.g., a table's row type),
60606072
<literal>d</literal> for a domain,
60616073
<literal>e</literal> for an enum type,
6062-
or <literal>p</literal> for a pseudo-type.
6074+
<literal>p</literal> for a pseudo-type, or
6075+
<literal>r</literal> for a range type.
60636076
See also <structfield>typrelid</structfield> and
60646077
<structfield>typbasetype</structfield>.
60656078
</entry>
@@ -6429,6 +6442,10 @@
64296442
<entry><literal>P</literal></entry>
64306443
<entry>Pseudo-types</entry>
64316444
</row>
6445+
<row>
6446+
<entry><literal>R</literal></entry>
6447+
<entry>Range types</entry>
6448+
</row>
64326449
<row>
64336450
<entry><literal>S</literal></entry>
64346451
<entry>String types</entry>

doc/src/sgml/extend.sgml

+12-11
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,13 @@
200200
<para>
201201
Five pseudo-types of special interest are <type>anyelement</>,
202202
<type>anyarray</>, <type>anynonarray</>, <type>anyenum</>,
203-
and <type>anyrange</>, which are collectively
204-
called <firstterm>polymorphic types</>. Any function declared
205-
using these types is said to be a <firstterm>polymorphic
206-
function</>. A polymorphic function can operate on many
207-
different data types, with the specific data type(s) being
208-
determined by the data types actually passed to it in a
209-
particular call.
203+
and <type>anyrange</>,
204+
which are collectively called <firstterm>polymorphic types</>.
205+
Any function declared using these types is said to be
206+
a <firstterm>polymorphic function</>. A polymorphic function can
207+
operate on many different data types, with the specific data type(s)
208+
being determined by the data types actually passed to it in a particular
209+
call.
210210
</para>
211211

212212
<para>
@@ -217,15 +217,16 @@
217217
data type, but in any given call they must all be the
218218
<emphasis>same</emphasis> actual type. Each
219219
position declared as <type>anyarray</type> can have any array data type,
220-
but similarly they must all be the same type. If there are
220+
but similarly they must all be the same type. And similarly,
221+
positions declared as <type>anyrange</type> must all be the same range
222+
type. Furthermore, if there are
221223
positions declared <type>anyarray</type> and others declared
222224
<type>anyelement</type>, the actual array type in the
223225
<type>anyarray</type> positions must be an array whose elements are
224226
the same type appearing in the <type>anyelement</type> positions.
225227
Similarly, if there are positions declared <type>anyrange</type>
226-
and others declared
227-
<type>anyelement</type>, the actual range type in the
228-
<type>anyrange</type> positions must be a range whose subtype is
228+
and others declared <type>anyelement</type>, the actual range type in
229+
the <type>anyrange</type> positions must be a range whose subtype is
229230
the same type appearing in the <type>anyelement</type> positions.
230231
<type>anynonarray</> is treated exactly the same as <type>anyelement</>,
231232
but adds the additional constraint that the actual type must not be

doc/src/sgml/func.sgml

+16-2
Original file line numberDiff line numberDiff line change
@@ -10525,18 +10525,32 @@ SELECT NULLIF(value, '(none)') ...
1052510525

1052610526
<row>
1052710527
<entry> <literal>@&gt;</literal> </entry>
10528-
<entry>contains</entry>
10528+
<entry>contains range</entry>
10529+
<entry><literal>int4range(2,4) @&gt; int4range(2,3)</literal></entry>
10530+
<entry><literal>t</literal></entry>
10531+
</row>
10532+
10533+
<row>
10534+
<entry> <literal>@&gt;</literal> </entry>
10535+
<entry>contains element</entry>
1052910536
<entry><literal>'[2011-01-01,2011-03-01)'::tsrange @&gt; '2011-01-10'::timestamp</literal></entry>
1053010537
<entry><literal>t</literal></entry>
1053110538
</row>
1053210539

1053310540
<row>
1053410541
<entry> <literal>&lt;@</literal> </entry>
10535-
<entry>is contained by</entry>
10542+
<entry>range is contained by</entry>
1053610543
<entry><literal>int4range(2,4) &lt;@ int4range(1,7)</literal></entry>
1053710544
<entry><literal>t</literal></entry>
1053810545
</row>
1053910546

10547+
<row>
10548+
<entry> <literal>&lt;@</literal> </entry>
10549+
<entry>element is contained by</entry>
10550+
<entry><literal>42 &lt;@ int4range(1,7)</literal></entry>
10551+
<entry><literal>f</literal></entry>
10552+
</row>
10553+
1054010554
<row>
1054110555
<entry> <literal>&amp;&amp;</literal> </entry>
1054210556
<entry>overlap (have points in common)</entry>

0 commit comments

Comments
 (0)