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

From Bruno Wolff III
Subject Re: ORDER BY and DISTINCT ON
Date
Msg-id 20031214144030.GA9284@wolff.to
Whole thread Raw
In response to Re: ORDER BY and DISTINCT ON  (Greg Stark <gsstark@mit.edu>)
List pgsql-hackers
On Sat, Dec 13, 2003 at 22:12:32 -0500, Greg Stark <gsstark@mit.edu> wrote:
> 
> 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.

You can make the result deterministic by using an initial order by
that uses the distinct expressions followed by the order by expressions.
After that is used to get which records will be returned, a second sort
is done using just the expressions on the order by clause.


pgsql-hackers by date:

Previous
From: Kurt Roeckx
Date:
Subject: Re: Walker/mutator prototype.
Next
From: Greg Stark
Date:
Subject: Re: Walker/mutator prototype.