Re: Aggregate ORDER BY patch
Andrew Gierth <andrew@tao11.riddles.org.uk>
From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: tgl@sss.pgh.pa.us (Tom Lane), pgsql-hackers@postgresql.org, Hitoshi Harada <umi.tanuki@gmail.com>
Date: 2009-12-15T21:01:05Z
Lists: pgsql-hackers
>>>>> "Tom" == Tom Lane <tgl@sss.pgh.pa.us> writes: >> Query-level DISTINCT shouldn't allow columns in the order by that >> aren't in the select list because those columns _do not exist_ at >> the point that ordering logically takes place (even though in the >> implementation, they might). >> This isn't the case for aggregate order by. Tom> I entirely disagree. Why should the semantics of this Tom> combination of ORDER BY and DISTINCT be different from what they Tom> are at the query top level? We made other decisions about this Tom> feature on the basis of making the two cases work alike, and I Tom> don't think you've made an adequate argument for making them act Tom> differently. A case could possibly be made that the behaviour of DISTINCT at top level is wrong, or at least less useful than need be. Notice that there are cases where agg(distinct x order by x) is nondeterministic while agg(distinct x order by x,y) is deterministic. In my view that alone is a good argument for allowing it. -- Andrew (irc:RhodiumToad)