<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><-></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><#></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><=></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>&&</literal>, <literal>@></literal>, and
<literal><@</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><-></literal>, <literal><#></literal>, and
<literal><=></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 <-> cube(array[0.5,0.5,0.5]) LIMIT 1;
</programlisting>
</para>
<para>
The <literal>~></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 ~> 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 ~> 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>