Skip to content

Commit 70c1245

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 8a17afe commit 70c1245

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

doc/src/sgml/func.sgml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11458,14 +11458,14 @@ SELECT NULLIF(value, '(none)') ...
1145811458
<row>
1145911459
<entry> <literal>@&gt;</literal> </entry>
1146011460
<entry>contains</entry>
11461-
<entry><literal>ARRAY[1,4,3] @&gt; ARRAY[3,1]</literal></entry>
11461+
<entry><literal>ARRAY[1,4,3] @&gt; ARRAY[3,1,3]</literal></entry>
1146211462
<entry><literal>t</literal></entry>
1146311463
</row>
1146411464

1146511465
<row>
1146611466
<entry> <literal>&lt;@</literal> </entry>
1146711467
<entry>is contained by</entry>
11468-
<entry><literal>ARRAY[2,7] &lt;@ ARRAY[1,7,4,2,6]</literal></entry>
11468+
<entry><literal>ARRAY[2,2,7] &lt;@ ARRAY[1,7,4,2,6]</literal></entry>
1146911469
<entry><literal>t</literal></entry>
1147011470
</row>
1147111471

@@ -11508,8 +11508,10 @@ SELECT NULLIF(value, '(none)') ...
1150811508
</table>
1150911509

1151011510
<para>
11511-
Array comparisons compare the array contents element-by-element,
11512-
using the default B-tree comparison function for the element data type.
11511+
The array ordering operators (<literal>&lt;</literal>,
11512+
<literal>&gt;=</literal>, etc) compare the array contents
11513+
element-by-element, using the default B-tree comparison function for
11514+
the element data type, and sort based on the first difference.
1151311515
In multidimensional arrays the elements are visited in row-major order
1151411516
(last subscript varies most rapidly).
1151511517
If the contents of two arrays are equal but the dimensionality is
@@ -11520,6 +11522,15 @@ SELECT NULLIF(value, '(none)') ...
1152011522
number of dimensions or subscript ranges were different.)
1152111523
</para>
1152211524

11525+
<para>
11526+
The array containment operators (<literal>&lt;@</literal>
11527+
and <literal>@&gt;</literal>) consider one array to be contained in
11528+
another one if each of its elements appears in the other one.
11529+
Duplicates are not treated specially, thus <literal>ARRAY[1]</literal>
11530+
and <literal>ARRAY[1,1]</literal> are each considered to contain the
11531+
other.
11532+
</para>
11533+
1152311534
<para>
1152411535
See <xref linkend="arrays"> for more details about array operator
1152511536
behavior. See <xref linkend="indexes-types"> for more details about

0 commit comments

Comments
 (0)