Re: [HACKERS] DISTINCT and ORDER BY bug?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Chris <chris(at)bitmead(dot)com>
Cc: Don Baccus <dhogaza(at)pacifier(dot)com>, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] DISTINCT and ORDER BY bug?
Date: 2000-02-07 15:56:43
Message-ID: 19716.949939003@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Chris <chris(at)bitmead(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2000-02-07 16:03:23 Re: [HACKERS] DISTINCT and ORDER BY bug?
Previous Message Jan Wieck 2000-02-07 15:47:11 Re: [HACKERS] New Globe