Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sEavA-002Np2-MC for pgsql-bugs@arkaria.postgresql.org; Tue, 04 Jun 2024 20:38:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sEav9-002VbF-0F for pgsql-bugs@arkaria.postgresql.org; Tue, 04 Jun 2024 20:38:15 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sEav8-002Vb6-Nz for pgsql-bugs@lists.postgresql.org; Tue, 04 Jun 2024 20:38:14 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sEav6-003TNZ-5s for pgsql-bugs@postgresql.org; Tue, 04 Jun 2024 20:38:13 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 454Kc40X584885; Tue, 4 Jun 2024 16:38:04 -0400 From: Tom Lane To: "David G. Johnston" cc: "Casey & Gina" , "pgsql-bugs@postgresql.org" Subject: Re: Arrays are sorted when using intarray subtraction operator In-reply-to: References: <0815AFF7-BE47-456B-896C-FB952CC52EE0@osss.net> Comments: In-reply-to "David G. Johnston" message dated "Tue, 04 Jun 2024 13:30:31 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <584883.1717533484.1@sss.pgh.pa.us> Date: Tue, 04 Jun 2024 16:38:04 -0400 Message-ID: <584884.1717533484@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > On Tuesday, June 4, 2024, Casey & Gina wrote: >> I've noticed that when using the `-` operator provided by the intarray >> extension, it appears to sort the results. Although I want the results >> sorted, I'd expect to have to additionally use the `sort` function it >> provides, as this behavior isn't documented. I don't want to rely on >> undocumented behavior, although it would simplify my queries to do so. Is >> the documentation lacking in this detail, or is it an unintended bug? > I would consider it an undocumented effect as to what the resultant array > with elements removed looks like. It's an implementation detail: sorting the values makes it easy to match up duplicates. > If you need to ensure you have a sorted > array use the sort function. Yeah. While I'd judge the implementation pretty unlikely to change, feel free to add an explicit sort call if you feel uncomfortable about relying on it. regards, tom lane