Commit 13cd97e6 authored by Tom Lane's avatar Tom Lane

Doc: clarify handling of duplicate elements in array containment tests.

The array <@ and @> operators do not worry about duplicates: if every
member of array X matches some element of array Y, then X is contained
in Y, even if several members of X get matched to the same Y member.
This was not explicitly stated in the docs though, so improve matters.

Discussion: https://postgr.es/m/156614120484.1310.310161642239149585@wrigleys.postgresql.org
parent 887248e9
...@@ -14058,14 +14058,14 @@ SELECT NULLIF(value, '(none)') ... ...@@ -14058,14 +14058,14 @@ SELECT NULLIF(value, '(none)') ...
<row> <row>
<entry> <literal>@&gt;</literal> </entry> <entry> <literal>@&gt;</literal> </entry>
<entry>contains</entry> <entry>contains</entry>
<entry><literal>ARRAY[1,4,3] @&gt; ARRAY[3,1]</literal></entry> <entry><literal>ARRAY[1,4,3] @&gt; ARRAY[3,1,3]</literal></entry>
<entry><literal>t</literal></entry> <entry><literal>t</literal></entry>
</row> </row>
<row> <row>
<entry> <literal>&lt;@</literal> </entry> <entry> <literal>&lt;@</literal> </entry>
<entry>is contained by</entry> <entry>is contained by</entry>
<entry><literal>ARRAY[2,7] &lt;@ ARRAY[1,7,4,2,6]</literal></entry> <entry><literal>ARRAY[2,2,7] &lt;@ ARRAY[1,7,4,2,6]</literal></entry>
<entry><literal>t</literal></entry> <entry><literal>t</literal></entry>
</row> </row>
...@@ -14108,8 +14108,10 @@ SELECT NULLIF(value, '(none)') ... ...@@ -14108,8 +14108,10 @@ SELECT NULLIF(value, '(none)') ...
</table> </table>
<para> <para>
Array comparisons compare the array contents element-by-element, The array ordering operators (<literal>&lt;</literal>,
using the default B-tree comparison function for the element data type. <literal>&gt;=</literal>, etc) compare the array contents
element-by-element, using the default B-tree comparison function for
the element data type, and sort based on the first difference.
In multidimensional arrays the elements are visited in row-major order In multidimensional arrays the elements are visited in row-major order
(last subscript varies most rapidly). (last subscript varies most rapidly).
If the contents of two arrays are equal but the dimensionality is If the contents of two arrays are equal but the dimensionality is
...@@ -14120,6 +14122,15 @@ SELECT NULLIF(value, '(none)') ... ...@@ -14120,6 +14122,15 @@ SELECT NULLIF(value, '(none)') ...
number of dimensions or subscript ranges were different.) number of dimensions or subscript ranges were different.)
</para> </para>
<para>
The array containment operators (<literal>&lt;@</literal>
and <literal>@&gt;</literal>) consider one array to be contained in
another one if each of its elements appears in the other one.
Duplicates are not treated specially, thus <literal>ARRAY[1]</literal>
and <literal>ARRAY[1,1]</literal> are each considered to contain the
other.
</para>
<para> <para>
See <xref linkend="arrays"/> for more details about array operator See <xref linkend="arrays"/> for more details about array operator
behavior. See <xref linkend="indexes-types"/> for more details about behavior. See <xref linkend="indexes-types"/> for more details about
...@@ -18277,7 +18288,7 @@ SELECT has_function_privilege('joeuser', 'myfunc(int, text)', 'execute'); ...@@ -18277,7 +18288,7 @@ SELECT has_function_privilege('joeuser', 'myfunc(int, text)', 'execute');
<row> <row>
<entry> <literal>@&gt;</literal> </entry> <entry> <literal>@&gt;</literal> </entry>
<entry>contains element</entry> <entry>contains element</entry>
<entry><literal>'{calvin=r*w/hobbes,hobbes=r*w*/postgres}'::aclitem[] @> 'calvin=r*w/hobbes'::aclitem</literal></entry> <entry><literal>'{calvin=r*w/hobbes,hobbes=r*w*/postgres}'::aclitem[] @&gt; 'calvin=r*w/hobbes'::aclitem</literal></entry>
<entry><literal>t</literal></entry> <entry><literal>t</literal></entry>
</row> </row>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment