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

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

From: hubert depesz lubaczewski <depesz(at)depesz(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: distinct on doesn't fail without order by? why?
Date: 2009-05-18 18:24:32
Message-ID: 20090518182432.GA9289@depesz.com (view raw or flat)
Thread:
Lists: pgsql-bugs
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?

# select distinct on (x) x, y from test;
 x | y
---+---
 1 | 2
 2 | 3
(2 rows)

# select * from test;
 x | y
---+---
 1 | 2
 2 | 3
 1 | 4
(3 rows)

Best regards,

depesz

-- 
Linkedin: http://www.linkedin.com/in/depesz  /  blog: http://www.depesz.com/
jid/gtalk: depesz(at)depesz(dot)com / aim:depeszhdl / skype:depesz_hdl / gg:6749007

Responses

pgsql-bugs by date

Next:From: Jeff DavisDate: 2009-05-18 21:56:33
Subject: Re: distinct on doesn't fail without order by? why?
Previous:From: Tom LaneDate: 2009-05-18 15:46:22
Subject: Re: BUG #4812: statistics not available on tables containing only hstore column

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