Re: Aggregate ORDER BY patch - Mailing list pgsql-hackers

From Andrew Gierth
Subject Re: Aggregate ORDER BY patch
Date
Msg-id 87ocn6pepf.fsf@news-spur.riddles.org.uk
Whole thread Raw
In response to Re: Aggregate ORDER BY patch  (Peter Eisentraut <peter_e@gmx.net>)
Responses Re: Aggregate ORDER BY patch
List pgsql-hackers
>>>>> "Peter" == Peter Eisentraut <peter_e@gmx.net> writes:
>> I'm not entirely convinced that adding ORDER BY here is a good idea,>> partly because it goes so far beyond the
spec
Peter> This is exactly the syntax that is in the spec AFAICT.

Right. The spec defines this syntax for array_agg and xmlagg (only).
The patch goes beyond the spec in that it allows ORDER BY for any
aggregate at all, and also allows combination of ORDER BY and DISTINCT
(the spec only allows DISTINCT with <general set operation> which
doesn't include array_agg or xmlagg, so there is nowhere that both are
allowed).

But it would be entirely unreasonable, the way postgres works, to
implement ORDER BY for only specific aggregates.

(Note also that combining ORDER BY and DISTINCT can change the
behaviour of DISTINCT. e.g.  foo(distinct x order by x using <<<) will
use whatever definition of equality is implied by the hypothetical <<<
operator when comparing values of x for distinctness.)

As for the null handling, the spec is no help there for this reason:
it allows DISTINCT only for <general set operation>, and for all
<general set operation>s whether DISTINCT or not, NULLs are always
discarded from the input before processing (i.e. the behaviour we
implement for strict aggregates). So even the fact that we allow
array_agg(distinct x) at all is going beyond the spec and therefore
doesn't have a defined result.

-- 
Andrew (irc:RhodiumToad)


pgsql-hackers by date:

Previous
From: Andrew Gierth
Date:
Subject: Re: Aggregate ORDER BY patch
Next
From: Tom Lane
Date:
Subject: Re: Experimental patch: generating BKI revisited