Re: Warts with SELECT DISTINCT - Mailing list pgsql-hackers

From Bruno Wolff III
Subject Re: Warts with SELECT DISTINCT
Date
Msg-id 20060504062153.GB26841@wolff.to
Whole thread Raw
In response to Re: Warts with SELECT DISTINCT  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Warts with SELECT DISTINCT  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Thu, May 04, 2006 at 01:13:20 -0400, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> 
> I think it's a fair point that we could allow "SELECT DISTINCT x ORDER BY
> foo(x)" if foo() is stable, but that does not imply that sorting by x is
> interchangeable with sorting by foo(x).  foo = abs is a trivial
> counterexample.

I misunderstood Greg's example. Sorting by (foo(x), x) is a suitable
replacement for sorting by foo(x). So that it would be OK to rewrite
SELECT DISTINCT x ORDER BY foo(x)
as
SELECT DISTINCT ON (foo(x), x) x ORDER BY foo(x)

Whether or not this is worthwhile to automate, I am not in a good position
to judge.


pgsql-hackers by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: Warts with SELECT DISTINCT
Next
From: Tom Lane
Date:
Subject: Re: Warts with SELECT DISTINCT