Re: Arrays are sorted when using intarray subtraction operator

Lists: Postg젠 토토SQL : Postg젠 토토SQL 메일 링리스트 : 2024-06-04 이후 PGSQL-BUGS 20:30
From: Casey & Gina <cg(at)osss(dot)net>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Arrays are sorted when using intarray subtraction operator
Date: 2024-06-04 20:00:44
Message-ID: 0815AFF7-BE47-456B-896C-FB952CC52EE0@osss.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

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?

Thanks,
--
Casey


From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: "Casey & Gina" <cg(at)osss(dot)net>
Cc: "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: Arrays are sorted when using intarray subtraction operator
Date: 2024-06-04 20:30:31
Message-ID: CAKFQuwaahssqGJ+USNutNdu3M4ud98Ary2fxopzzshAxUvCPtw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: Postg젠 토토SQL : Postg젠 토토SQL 메일 링리스트 : 2024-06-04 이후 PGSQL-BUGS 20:30

On Tuesday, June 4, 2024, Casey & Gina <cg(at)osss(dot)net> 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. If you need to ensure you have a sorted
array use the sort function.

David J.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: "Casey & Gina" <cg(at)osss(dot)net>, "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: Arrays are sorted when using intarray subtraction operator
Date: 2024-06-04 20:38:04
Message-ID: 584884.1717533484@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> On Tuesday, June 4, 2024, Casey & Gina <cg(at)osss(dot)net> 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