"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