From 216bcf583802011365b8bb038b4e73f143e857b2 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 23 Sep 2019 12:37:04 -0400 Subject: [PATCH] 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 --- doc/src/sgml/func.sgml | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index f5c1db6873..432dbad868 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -14004,14 +14004,14 @@ SELECT NULLIF(value, '(none)') ... @> contains - ARRAY[1,4,3] @> ARRAY[3,1] + ARRAY[1,4,3] @> ARRAY[3,1,3] t <@ is contained by - ARRAY[2,7] <@ ARRAY[1,7,4,2,6] + ARRAY[2,2,7] <@ ARRAY[1,7,4,2,6] t @@ -14054,8 +14054,10 @@ SELECT NULLIF(value, '(none)') ... - Array comparisons compare the array contents element-by-element, - using the default B-tree comparison function for the element data type. + The array ordering operators (<, + >=, 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 (last subscript varies most rapidly). If the contents of two arrays are equal but the dimensionality is @@ -14066,6 +14068,15 @@ SELECT NULLIF(value, '(none)') ... number of dimensions or subscript ranges were different.) + + The array containment operators (<@ + and @>) 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 ARRAY[1] + and ARRAY[1,1] are each considered to contain the + other. + + See for more details about array operator behavior. See for more details about @@ -18223,7 +18234,7 @@ SELECT has_function_privilege('joeuser', 'myfunc(int, text)', 'execute'); @> contains element - '{calvin=r*w/hobbes,hobbes=r*w*/postgres}'::aclitem[] @> 'calvin=r*w/hobbes'::aclitem + '{calvin=r*w/hobbes,hobbes=r*w*/postgres}'::aclitem[] @> 'calvin=r*w/hobbes'::aclitem t