Re: Aggregate ORDER BY patch

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
Cc: pgsql-hackers(at)postgresql(dot)org, Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com>
Subject: Re: Aggregate ORDER BY patch
Date: 2009-12-15 21:10:39
Message-ID: 14390.1260911439@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk> writes:
> Notice that there are cases where agg(distinct x order by x) is
> nondeterministic while agg(distinct x order by x,y) is deterministic.

Well, I think what you're really describing is a case where you're using
the wrong sort opclass. If the aggregate can distinguish two values of
x, and the sort operator can't, use another sort operator that can.

If we really wanted to take the above seriously, my opinion is that
we ought to introduce DISTINCT ON in aggregates. However, at that
point you lose the argument of standard syntax, so it's not real
clear why you shouldn't just fall back on
select agg(x) from (select distinct on (x) x ... order by x,y)

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Kurt Harriman 2009-12-15 21:12:47 Re: Patch: Remove gcc dependency in definition of inline functions
Previous Message Andrew Gierth 2009-12-15 21:01:05 Re: Aggregate ORDER BY patch