Skip site navigation (1) Skip section navigation (2)

Re: distinct on doesn't fail without order by? why?

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: depesz(at)depesz(dot)com
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: distinct on doesn't fail without order by? why?
Date: 2009-05-18 21:56:33
Message-ID: 1242683793.26009.29.camel@monkey-cat.sm.truviso.com (view raw or flat)
Thread:
Lists: pgsql-bugs
On Mon, 2009-05-18 at 20:24 +0200, hubert depesz lubaczewski wrote:
> I was under impression that select distinct on (xx) ...
> will fail if xx doesn't match the left most part of order by. i.e. it
> requires order by xx, while allowing order by xx, something, else.
> 
> But it seems you can run the query with no order by clause at all.
> 
> is it intentional?

This is documented behavior:

"Note that the 'first row' of each set is unpredictable unless ORDER BY
is used to ensure that the desired row appears first."

http://www.postgresql.org/docs/8.4/static/sql-select.html#SQL-DISTINCT

Regards,
	Jeff Davis


In response to

pgsql-bugs by date

Next:From: Tom LaneDate: 2009-05-18 22:57:40
Subject: Re: distinct on doesn't fail without order by? why?
Previous:From: hubert depesz lubaczewskiDate: 2009-05-18 18:24:32
Subject: distinct on doesn't fail without order by? why?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group