Re: Aggregate ORDER BY patch

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Marko Tiikkaja <marko.tiikkaja@cs.helsinki.fi>
Cc: Andrew Gierth <andrew@tao11.riddles.org.uk>, pgsql-hackers@postgresql.org, Hitoshi Harada <umi.tanuki@gmail.com>
Date: 2009-12-19T19:34:06Z
Lists: pgsql-hackers
Marko Tiikkaja <marko.tiikkaja@cs.helsinki.fi> writes:
> On 2009-12-15 23:10 +0200, Tom Lane wrote:
>> If we really wanted to take the above seriously, my opinion is that
>> we ought to introduce DISTINCT ON in aggregates.

> FWIW, in my opinion the idea behind this patch is to not fall back on 
> hacks like that.  This patch already goes beyond the standard and having 
> this seems like a useful feature in some cases.  Although the DISTINCT 
> ON syntax would have a bit more resemblance on the existing syntax, I'd 
> still like to see agg(distinct x order by x,y).

I remain entirely unconvinced.  If DISTINCT + ORDER BY work differently
inside aggregates than at query level, we're going to forever be
explaining the difference, fielding bug reports, etc.  Even documenting
the difference would be a serious PITA considering how subtle it is
(AFAICS Andrew's submitted doc patch failed to address the point).

I'm not against the idea of introducing DISTINCT ON here, though I think
perhaps we ought to wait for a release or so and see if there's really
any field demand for it.

			regards, tom lane