Re: [HACKERS] DISTINCT and ORDER BY bug? - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [HACKERS] DISTINCT and ORDER BY bug?
Date
Msg-id 19716.949939003@sss.pgh.pa.us
Whole thread Raw
In response to Re: [HACKERS] DISTINCT and ORDER BY bug?  (Chris <chris@bitmead.com>)
List pgsql-hackers
Chris <chris@bitmead.com> writes:
>> select distinct x from foo order by y;
>> 
>> which produces ill-defined results.

> Why is this ill-defined? If y is in x then it is also distinct

Huh?  The query specifies distinct values of x, and only x.
Consider    x    y
    1    1    1    10    2    0    2    11

"select distinct x" ought to produce one row with x=1, and one row with
x=2, and nothing else.  If it implicitly did the distinct on y as well,
you'd get four rows with two x=1 and two x=2, which is not my idea of
"distinct x".  But if you don't have four rows out, then there's no
meaningful way to order by y.

6.5.3 in fact produces four rows from this query, which is generally
conceded to be broken behavior.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Don Baccus
Date:
Subject: Re: [HACKERS] follow-up on PC Week Labs benchmark results
Next
From: wieck@debis.com (Jan Wieck)
Date:
Subject: Re: [HACKERS] New Globe