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

Поиск
Список
Период
Сортировка
От Merlin Moncure
Тема Re: [GENERAL] Are multiple array_aggs going to be in the same order?
Дата
Msg-id CAHyXU0zN0Xds9X1Qnw=T3bj-UQ2je5g9vzFtHDrcxUzvf4sHeg@mail.gmail.com
обсуждение исходный текст
Ответ на Re: [GENERAL] Are multiple array_aggs going to be in the same order?  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: [GENERAL] Are multiple array_aggs going to be in the same order?
Список pgsql-general
On Mon, Apr 10, 2017 at 12:01 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Merlin Moncure <mmoncure@gmail.com> writes:
>> On Sun, Apr 9, 2017 at 4:27 PM, Guyren Howe <guyren@gmail.com> wrote:
>>> If I do a SELECT with a GROUP_BY and multiple ARRAY_AGGs, will the ARRAY_AGGs be guaranteed to have entries in the
same(ie corresponding) order? 
>>>
>>> eg
>>>
>>> SELECT
>>> u.name,
>>> ARRAY_AGG(o.order_date) AS order_dates,
>>> ARRAY_AGG(o.order_total) AS order_totals
>>> FROM
>>> user u JOIN
>>> orders o USING (user_id)
>>> GROUP BY
>>> u.user_id
>
>> It is unsafe to rely on aggregation order unless specified -- you can
>> add ORDER BY to the aggregation clause.
>
> You definitely can't assume anything about the order in which the FROM
> clause will deliver rows, but I think that's not quite what the question
> was.  If I read it right, the OP wants to be sure that the two aggregate
> functions will see the data in the *same* unspecified order.  I think
> that's a pretty safe assumption.  The server would have to go way
> out of its way to do differently, and it doesn't.

Sure, but isn't it fair to consider that an implementation artifact?
If his code depends on that ordering being the same across aggregate
functions, and the SQL standard doesn't specify that (I guess it
might, but I'm skeptical), he ought to specify that for clarify at the
very least.

merlin


В списке pgsql-general по дате отправления:

Предыдущее
От: Paul Jungwirth
Дата:
Сообщение: Re: [GENERAL] Are multiple array_aggs going to be in the same order?
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: [GENERAL] Are multiple array_aggs going to be in the same order?