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

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Guyren Howe <guyren(at)gmail(dot)com>
Cc: 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 16:33:28
Message-ID: CAHyXU0yMpkrvcOd7-9oN5fd_27WUeaF2K9ccMydo=WX5G66CRg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, Apr 9, 2017 at 4:27 PM, Guyren Howe <guyren(at)gmail(dot)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.

merlin

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2017-04-10 17:01:29 Re: Are multiple array_aggs going to be in the same order?
Previous Message Tom DalPozzo 2017-04-10 16:31:55 Re: WAL being written during SELECT * query