Home Explore Blog CI



postgresql

3rd chunk of `doc/src/sgml/cube.sgml`
17cacc733439c6a090ebfe8853c5f85e8a16cdfe38f13ccb0000000100000fa6
 <parameter>k</parameter>-th dimension, <parameter>n</parameter> = 2
        * <parameter>k</parameter> means upper bound of
        <parameter>k</parameter>-th dimension.  Negative
        <parameter>n</parameter> denotes the inverse value of the corresponding
        positive coordinate.  This operator is designed for KNN-GiST support.
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <type>cube</type> <literal>&lt;-&gt;</literal> <type>cube</type>
        <returnvalue>float8</returnvalue>
       </para>
       <para>
        Computes the Euclidean distance between the two cubes.
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <type>cube</type> <literal>&lt;#&gt;</literal> <type>cube</type>
        <returnvalue>float8</returnvalue>
       </para>
       <para>
        Computes the taxicab (L-1 metric) distance between the two cubes.
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <type>cube</type> <literal>&lt;=&gt;</literal> <type>cube</type>
        <returnvalue>float8</returnvalue>
       </para>
       <para>
        Computes the Chebyshev (L-inf metric) distance between the two cubes.
       </para></entry>
      </row>
     </tbody>
   </tgroup>
  </table>

  <para>
   In addition to the above operators, the usual comparison
   operators shown in <xref linkend="functions-comparison-op-table"/> are
   available for type <type>cube</type>.  These
   operators first compare the first coordinates, and if those are equal,
   compare the second coordinates, etc.  They exist mainly to support the
   b-tree index operator class for <type>cube</type>, which can be useful for
   example if you would like a UNIQUE constraint on a <type>cube</type> column.
   Otherwise, this ordering is not of much practical use.
  </para>

  <para>
   The <filename>cube</filename> module also provides a GiST index operator class for
   <type>cube</type> values.
   A <type>cube</type> GiST index can be used to search for values using the
   <literal>=</literal>, <literal>&amp;&amp;</literal>, <literal>@&gt;</literal>, and
   <literal>&lt;@</literal> operators in <literal>WHERE</literal> clauses.
  </para>

  <para>
   In addition, a <type>cube</type> GiST index can be used to find nearest
   neighbors using the metric operators
   <literal>&lt;-&gt;</literal>, <literal>&lt;#&gt;</literal>, and
   <literal>&lt;=&gt;</literal> in <literal>ORDER BY</literal> clauses.
   For example, the nearest neighbor of the 3-D point (0.5, 0.5, 0.5)
   could be found efficiently with:
<programlisting>
SELECT c FROM test ORDER BY c &lt;-&gt; cube(array[0.5,0.5,0.5]) LIMIT 1;
</programlisting>
  </para>

  <para>
   The <literal>~&gt;</literal> operator can also be used in this way to
   efficiently retrieve the first few values sorted by a selected coordinate.
   For example, to get the first few cubes ordered by the first coordinate
   (lower left corner) ascending one could use the following query:
<programlisting>
SELECT c FROM test ORDER BY c ~&gt; 1 LIMIT 5;
</programlisting>
   And to get 2-D cubes ordered by the first coordinate of the upper right
   corner descending:
<programlisting>
SELECT c FROM test ORDER BY c ~&gt; 3 DESC LIMIT 5;
</programlisting>
  </para>

  <para>
   <xref linkend="cube-functions-table"/> shows the available functions.
  </para>

  <table id="cube-functions-table">
   <title>Cube Functions</title>
    <tgroup cols="1">
     <thead>
      <row>
       <entry role="func_table_entry"><para role="func_signature">
        Function
       </para>
       <para>
        Description
       </para>
       <para>
        Example(s)
       </para></entry>
      </row>
     </thead>

     <tbody>
      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <function>cube</function> ( <type>float8</type>

Title: Cube Data Type Functions and Indexing
Summary
The cube data type provides various functions and indexing capabilities, including GiST index operator classes for efficient searching and nearest neighbor queries. The available functions and operators allow for calculations such as Euclidean distance, taxicab distance, and Chebyshev distance between cubes, as well as coordinate extraction and comparison. The indexing capabilities enable efficient retrieval of cubes based on various criteria, including proximity to a given point or ordering by specific coordinates.