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

From Tom Lane
Subject Re: ORDER BY and DISTINCT ON
Date
Msg-id 3345.1071443373@sss.pgh.pa.us
Whole thread Raw
In response to Re: ORDER BY and DISTINCT ON  (Greg Stark <gsstark@mit.edu>)
Responses Re: ORDER BY and DISTINCT ON  (Neil Conway <neilc@samurai.com>)
Re: ORDER BY and DISTINCT ON  (Bruno Wolff III <bruno@wolff.to>)
List pgsql-hackers
Greg Stark <gsstark@mit.edu> writes:
> So, like DISTINCT ON, GROUP BY also insists on the user providing the
> ORDER BY clause. I suppose you could argue postgres could implicitly
> introduce an extra sort step when the user-provided ORDER BY doesn't
> match the GROUP BY or DISTINCT ON clause but it seems like the user is
> probably confused if he really wants a random record and then sort on
> columns that weren't sorted previous to the DISTINCT ON.

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.
        regards, tom lane


pgsql-hackers by date:

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