From: | Bruno Wolff III <bruno(at)wolff(dot)to> |
---|---|
To: | Greg Stark <gsstark(at)mit(dot)edu> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: ORDER BY and DISTINCT ON |
Date: | 2003-12-14 14:40:30 |
Message-ID: | 20031214144030.GA9284@wolff.to |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Sat, Dec 13, 2003 at 22:12:32 -0500,
Greg Stark <gsstark(at)mit(dot)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.
From | Date | Subject | |
---|---|---|---|
Next Message | Greg Stark | 2003-12-14 16:52:20 | Re: Walker/mutator prototype. |
Previous Message | Kurt Roeckx | 2003-12-14 13:30:57 | Re: Walker/mutator prototype. |