Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 13cd97e

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 887248e commit 13cd97e

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

doc/src/sgml/func.sgml

+16-5
Original file line numberDiff line numberDiff line change
@@ -14058,14 +14058,14 @@ SELECT NULLIF(value, '(none)') ...
1405814058
<row>
1405914059
<entry> <literal>@&gt;</literal> </entry>
1406014060
<entry>contains</entry>
14061-
<entry><literal>ARRAY[1,4,3] @&gt; ARRAY[3,1]</literal></entry>
14061+
<entry><literal>ARRAY[1,4,3] @&gt; ARRAY[3,1,3]</literal></entry>
1406214062
<entry><literal>t</literal></entry>
1406314063
</row>
1406414064

1406514065
<row>
1406614066
<entry> <literal>&lt;@</literal> </entry>
1406714067
<entry>is contained by</entry>
14068-
<entry><literal>ARRAY[2,7] &lt;@ ARRAY[1,7,4,2,6]</literal></entry>
14068+
<entry><literal>ARRAY[2,2,7] &lt;@ ARRAY[1,7,4,2,6]</literal></entry>
1406914069
<entry><literal>t</literal></entry>
1407014070
</row>
1407114071

@@ -14108,8 +14108,10 @@ SELECT NULLIF(value, '(none)') ...
1410814108
</table>
1410914109

1411014110
<para>
14111-
Array comparisons compare the array contents element-by-element,
14112-
using the default B-tree comparison function for the element data type.
14111+
The array ordering operators (<literal>&lt;</literal>,
14112+
<literal>&gt;=</literal>, etc) compare the array contents
14113+
element-by-element, using the default B-tree comparison function for
14114+
the element data type, and sort based on the first difference.
1411314115
In multidimensional arrays the elements are visited in row-major order
1411414116
(last subscript varies most rapidly).
1411514117
If the contents of two arrays are equal but the dimensionality is
@@ -14120,6 +14122,15 @@ SELECT NULLIF(value, '(none)') ...
1412014122
number of dimensions or subscript ranges were different.)
1412114123
</para>
1412214124

14125+
<para>
14126+
The array containment operators (<literal>&lt;@</literal>
14127+
and <literal>@&gt;</literal>) consider one array to be contained in
14128+
another one if each of its elements appears in the other one.
14129+
Duplicates are not treated specially, thus <literal>ARRAY[1]</literal>
14130+
and <literal>ARRAY[1,1]</literal> are each considered to contain the
14131+
other.
14132+
</para>
14133+
1412314134
<para>
1412414135
See <xref linkend="arrays"/> for more details about array operator
1412514136
behavior. See <xref linkend="indexes-types"/> for more details about
@@ -18277,7 +18288,7 @@ SELECT has_function_privilege('joeuser', 'myfunc(int, text)', 'execute');
1827718288
<row>
1827818289
<entry> <literal>@&gt;</literal> </entry>
1827918290
<entry>contains element</entry>
18280-
<entry><literal>'{calvin=r*w/hobbes,hobbes=r*w*/postgres}'::aclitem[] @> 'calvin=r*w/hobbes'::aclitem</literal></entry>
18291+
<entry><literal>'{calvin=r*w/hobbes,hobbes=r*w*/postgres}'::aclitem[] @&gt; 'calvin=r*w/hobbes'::aclitem</literal></entry>
1828118292
<entry><literal>t</literal></entry>
1828218293
</row>
1828318294

0 commit comments

Comments
 (0)