pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Arrays are sorted when using intarray subtraction operator
3+ messages / 3 participants
[nested] [flat]

* Arrays are sorted when using intarray subtraction operator
@ 2024-06-04 20:00  Casey & Gina <cg@osss.net>
  0 siblings, 1 reply; 3+ messages in thread

From: Casey & Gina @ 2024-06-04 20:00 UTC (permalink / raw)
  To: 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




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Arrays are sorted when using intarray subtraction operator
@ 2024-06-04 20:30  David G. Johnston <david.g.johnston@gmail.com>
  parent: Casey & Gina <cg@osss.net>
  0 siblings, 1 reply; 3+ messages in thread

From: David G. Johnston @ 2024-06-04 20:30 UTC (permalink / raw)
  To: Casey & Gina <cg@osss.net>; +Cc: pgsql-bugs

On Tuesday, June 4, 2024, Casey & Gina <cg@osss.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.

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Arrays are sorted when using intarray subtraction operator
@ 2024-06-04 20:38  Tom Lane <tgl@sss.pgh.pa.us>
  parent: David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2024-06-04 20:38 UTC (permalink / raw)
  To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: Casey & Gina <cg@osss.net>; pgsql-bugs

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





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2024-06-04 20:38 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-06-04 20:00 Arrays are sorted when using intarray subtraction operator Casey & Gina <cg@osss.net>
2024-06-04 20:30 ` David G. Johnston <david.g.johnston@gmail.com>
2024-06-04 20:38   ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox