Skip to content

Commit 0652c39

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 096d34c commit 0652c39

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
@@ -12591,14 +12591,14 @@ SELECT NULLIF(value, '(none)') ...
1259112591
<row>
1259212592
<entry> <literal>@&gt;</literal> </entry>
1259312593
<entry>contains</entry>
12594-
<entry><literal>ARRAY[1,4,3] @&gt; ARRAY[3,1]</literal></entry>
12594+
<entry><literal>ARRAY[1,4,3] @&gt; ARRAY[3,1,3]</literal></entry>
1259512595
<entry><literal>t</literal></entry>
1259612596
</row>
1259712597

1259812598
<row>
1259912599
<entry> <literal>&lt;@</literal> </entry>
1260012600
<entry>is contained by</entry>
12601-
<entry><literal>ARRAY[2,7] &lt;@ ARRAY[1,7,4,2,6]</literal></entry>
12601+
<entry><literal>ARRAY[2,2,7] &lt;@ ARRAY[1,7,4,2,6]</literal></entry>
1260212602
<entry><literal>t</literal></entry>
1260312603
</row>
1260412604

@@ -12641,8 +12641,10 @@ SELECT NULLIF(value, '(none)') ...
1264112641
</table>
1264212642

1264312643
<para>
12644-
Array comparisons compare the array contents element-by-element,
12645-
using the default B-tree comparison function for the element data type.
12644+
The array ordering operators (<literal>&lt;</literal>,
12645+
<literal>&gt;=</literal>, etc) compare the array contents
12646+
element-by-element, using the default B-tree comparison function for
12647+
the element data type, and sort based on the first difference.
1264612648
In multidimensional arrays the elements are visited in row-major order
1264712649
(last subscript varies most rapidly).
1264812650
If the contents of two arrays are equal but the dimensionality is
@@ -12653,6 +12655,15 @@ SELECT NULLIF(value, '(none)') ...
1265312655
number of dimensions or subscript ranges were different.)
1265412656
</para>
1265512657

12658+
<para>
12659+
The array containment operators (<literal>&lt;@</literal>
12660+
and <literal>@&gt;</literal>) consider one array to be contained in
12661+
another one if each of its elements appears in the other one.
12662+
Duplicates are not treated specially, thus <literal>ARRAY[1]</literal>
12663+
and <literal>ARRAY[1,1]</literal> are each considered to contain the
12664+
other.
12665+
</para>
12666+
1265612667
<para>
1265712668
See <xref linkend="arrays"> for more details about array operator
1265812669
behavior. See <xref linkend="indexes-types"> for more details about

0 commit comments

Comments
 (0)