Re: Are multiple array_aggs going to be in the same order?

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Guyren Howe <guyren(at)gmail(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Are multiple array_aggs going to be in the same order?
Date: 2017-04-10 19:13:22
Message-ID: CAHyXU0xgtJW-MGrLhzGJw78LcHybbc=b4gd9CPn76vfOjaJKTg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Apr 10, 2017 at 1:43 PM, Merlin Moncure <mmoncure(at)gmail(dot)com> wrote:
> On Mon, Apr 10, 2017 at 1:35 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>
>> Yes, and in fact we documented the ORDER-BY-in-subselect solution back
>> before we had the ORDER-BY-in-aggregate feature. I don't remember exactly
>> where, but I'm sure it's still described somewhere. So it is documented
>> behavior that an aggregate without its own ORDER BY will see the rows in
>> whatever order the FROM clause supplies them.
>
> The documentation is a bit ambiguous on the topic TBH. Via
> https://www.postgresql.org/docs/9.6/static/functions-aggregate.html:
>
> "The aggregate functions array_agg, json_agg, jsonb_agg,
> json_object_agg, jsonb_object_agg, string_agg, and xmlagg, as well as
> similar user-defined aggregate functions, produce meaningfully
> different result values depending on the order of the input values.
> This ordering is unspecified by default, but can be controlled by
> writing an ORDER BY clause within the aggregate call, as shown in
> Section 4.2.7. Alternatively, supplying the input values from a sorted
> subquery will usually work.
<snip>

What do you think about injecting the following lingo?

... depending on the order of the input values. This ordering is
unspecified by default, but can be controlled by ...

would be changed to

... depending on the order of the input values. Input value ordering
will be consistent across multiple order dependent aggregate functions
across the same grouping but is otherwise unspecified by default as
long as all there is no explicit ordering for any aggregate function
in the grouping. Furthermore, input value ordering can be controlled
by ...

merlin

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2017-04-10 19:19:40 Re: Are multiple array_aggs going to be in the same order?
Previous Message Paul Jungwirth 2017-04-10 18:58:24 Re: Are multiple array_aggs going to be in the same order?