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

From Neil Conway
Subject Re: ORDER BY and DISTINCT ON
Date
Msg-id 87fzfmg5p4.fsf@mailbox.samurai.com
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
List pgsql-hackers
Tom Lane <tgl@sss.pgh.pa.us> writes:
> 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").

Does the non-determinism you're referring to result from an ORDER BY
on a non-deterministic expression, or the non-determinism that results
from picking an effectively random row because the ORDER BY isn't
sufficient?

I searched the archives and found Stephen Szabo's comment[1] that:
 The query you've written is potential non-deterministic if you have a people_id that has multiple rows with different
lastnames that meet the where clause.
 

Which seems like an unconvincing justification for rejecting the
query: we accept DISTINCT ON with no ORDER BY clause at all, for
example.

-Neil

[1] http://archives.postgresql.org/pgsql-hackers/2001-07/msg00588.php



pgsql-hackers by date:

Previous
From: Christopher Kings-Lynne
Date:
Subject: Re: Resurrecting pg_upgrade
Next
From: Tom Lane
Date:
Subject: Re: Resurrecting pg_upgrade