On Mon, 2024-03-18 at 08:21 +0000, PG Doc comments form wrote:
> Page: https://www.postgresql.org/docs/16/intarray.html
> 
> Hi,
> I recently ran into an unusual issue with the intarray extension where if
> you subtract one array from another the result is *also* sorted and
> de-duplicated. The documentation does not seem to imply that this should be
> the case, stating only that the operator "removes elements of the right
> array from the left array" and not that it also de-duplicates and sorts the
> result... It seems to only occur when subtracting an array. Is this the
> intended behavior?
> 
> SELECT '{3,1,1,2,2,2}'::int[] - 1; --> {3,2,2,2} as you would expect
> SELECT '{3,1,1,2,2,2}'::int[] - '{1}'::int[]; --> {2,3} instead of
> {3,2,2,2}

There is no harm in documenting that; I propose the attached patch.

Yours,
Laurenz Albe
From 96a7fed7be768c047f8a74a4431716da0beb0e28 Mon Sep 17 00:00:00 2001
From: Laurenz Albe <laurenz.a...@cybertec.at>
Date: Mon, 18 Mar 2024 16:59:43 +0100
Subject: [PATCH v1] Documentation fix for intarray's "-" operator

Document that int[] - int[] removes duplicates as well as
elements of the right array.

Discussion: https://postgr.es/m/171075007381.7104.7931589808177869854%40wrigleys.postgresql.org
---
 doc/src/sgml/intarray.sgml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/src/sgml/intarray.sgml b/doc/src/sgml/intarray.sgml
index c72d49b01d..ec1d525042 100644
--- a/doc/src/sgml/intarray.sgml
+++ b/doc/src/sgml/intarray.sgml
@@ -312,7 +312,7 @@
         <returnvalue>integer[]</returnvalue>
        </para>
        <para>
-        Removes elements of the right array from the left array.
+        Removes elements of the right array and duplicate entries from the left array.
        </para></entry>
       </row>
 
-- 
2.44.0

Reply via email to