Skip to content

Commit 216bcf5

Browse files
committed
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
1 parent a25fb9c commit 216bcf5

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

doc/src/sgml/func.sgml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14004,14 +14004,14 @@ SELECT NULLIF(value, '(none)') ...
1400414004
<row>
1400514005
<entry> <literal>@&gt;</literal> </entry>
1400614006
<entry>contains</entry>
14007-
<entry><literal>ARRAY[1,4,3] @&gt; ARRAY[3,1]</literal></entry>
14007+
<entry><literal>ARRAY[1,4,3] @&gt; ARRAY[3,1,3]</literal></entry>
1400814008
<entry><literal>t</literal></entry>
1400914009
</row>
1401014010

1401114011
<row>
1401214012
<entry> <literal>&lt;@</literal> </entry>
1401314013
<entry>is contained by</entry>
14014-
<entry><literal>ARRAY[2,7] &lt;@ ARRAY[1,7,4,2,6]</literal></entry>
14014+
<entry><literal>ARRAY[2,2,7] &lt;@ ARRAY[1,7,4,2,6]</literal></entry>
1401514015
<entry><literal>t</literal></entry>
1401614016
</row>
1401714017

@@ -14054,8 +14054,10 @@ SELECT NULLIF(value, '(none)') ...
1405414054
</table>
1405514055

1405614056
<para>
14057-
Array comparisons compare the array contents element-by-element,
14058-
using the default B-tree comparison function for the element data type.
14057+
The array ordering operators (<literal>&lt;</literal>,
14058+
<literal>&gt;=</literal>, etc) compare the array contents
14059+
element-by-element, using the default B-tree comparison function for
14060+
the element data type, and sort based on the first difference.
1405914061
In multidimensional arrays the elements are visited in row-major order
1406014062
(last subscript varies most rapidly).
1406114063
If the contents of two arrays are equal but the dimensionality is
@@ -14066,6 +14068,15 @@ SELECT NULLIF(value, '(none)') ...
1406614068
number of dimensions or subscript ranges were different.)
1406714069
</para>
1406814070

14071+
<para>
14072+
The array containment operators (<literal>&lt;@</literal>
14073+
and <literal>@&gt;</literal>) consider one array to be contained in
14074+
another one if each of its elements appears in the other one.
14075+
Duplicates are not treated specially, thus <literal>ARRAY[1]</literal>
14076+
and <literal>ARRAY[1,1]</literal> are each considered to contain the
14077+
other.
14078+
</para>
14079+
1406914080
<para>
1407014081
See <xref linkend="arrays"/> for more details about array operator
1407114082
behavior. See <xref linkend="indexes-types"/> for more details about
@@ -18223,7 +18234,7 @@ SELECT has_function_privilege('joeuser', 'myfunc(int, text)', 'execute');
1822318234
<row>
1822418235
<entry> <literal>@&gt;</literal> </entry>
1822518236
<entry>contains element</entry>
18226-
<entry><literal>'{calvin=r*w/hobbes,hobbes=r*w*/postgres}'::aclitem[] @> 'calvin=r*w/hobbes'::aclitem</literal></entry>
18237+
<entry><literal>'{calvin=r*w/hobbes,hobbes=r*w*/postgres}'::aclitem[] @&gt; 'calvin=r*w/hobbes'::aclitem</literal></entry>
1822718238
<entry><literal>t</literal></entry>
1822818239
</row>
1822918240

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy