Re: ARRAY_AGG(DISTINCT a ORDER BY b) Error

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David Johnston" <polobo(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: ARRAY_AGG(DISTINCT a ORDER BY b) Error
Date: 2011-08-31 23:10:23
Message-ID: 6119.1314832223@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"David Johnston" <polobo(at)yahoo(dot)com> writes:
> "in an aggregate with DISTINCT, ORDER BY expressions must appear in argument
> list"

> Why?

Because the results are ill-defined otherwise. In your example,

> ... ARRAY_AGG(DISTINCT accountnumber ORDER BY amount DESC) ...

there may be many rows with the same "accountnumber" and yet different
"amount" values. Which of those amounts should be used as the sort key
for the aggregated row?

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thom Brown 2011-08-31 23:12:00 Re: ARRAY_AGG(DISTINCT a ORDER BY b) Error
Previous Message David Johnston 2011-08-31 22:54:37 ARRAY_AGG(DISTINCT a ORDER BY b) Error