Re: ORDER BY and DISTINCT ON - Mailing list pgsql-hackers

From Bruno Wolff III
Subject Re: ORDER BY and DISTINCT ON
Date
Msg-id 20031215025106.GA15847@wolff.to
Whole thread Raw
In response to Re: ORDER BY and DISTINCT ON  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: ORDER BY and DISTINCT ON  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Sun, Dec 14, 2003 at 18:09:33 -0500, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> 
> This was discussed before --- see the archives.  I believe the
> conclusion was that the results would actually be nondeterministic
> if we used two sort steps (that's what the code comment means by
> "rather unpredictable").  This is not unrelated to the reasons why
> people consider DISTINCT ON to be a messy feature ... ideally it
> should be orthogonal to ORDER BY, but it simply isn't.

If the sort used to select the records sorts on both the distinct
expressions and the order by expressions you will get a sensible
deterministic result. That result can then be sorted using just
the order by expressions.


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Resurrecting pg_upgrade
Next
From: Alvaro Herrera
Date:
Subject: Re: Resurrecting pg_upgrade