Re: [GENERAL] Distinct on a non-sort column

2011-11-06 Thread Cstdenis
On 11/5/2011 4:11 PM, Tom Lane wrote: Cstdenis writes: If I understand that you are proposing as select * from (select distinct on (user_id) * from stories as s order by user_id) as foo order by date_submitted desc limit 10; No, you always need to sort by *more

Re: [GENERAL] Distinct on a non-sort column

2011-11-05 Thread Tom Lane
Cstdenis writes: > If I understand that you are proposing as > select * from > (select distinct on (user_id) * from stories as s order > by user_id) as foo > order by date_submitted desc limit 10; No, you always need to sort by *more* columns than are listed in DISTI

Re: [GENERAL] Distinct on a non-sort column

2011-11-05 Thread Cstdenis
On 11/5/2011 12:49 PM, Tom Lane wrote: Cstdenis writes: I am trying to write a query that selects recent submissions (sorted by submission_date) but only selects the most recent one for each user_id. example query: /select distinct on (user_id) * from stories order by date_submitted desc limit

Re: [GENERAL] Distinct on a non-sort column

2011-11-05 Thread John R Pierce
On 11/05/11 11:39 AM, Cstdenis wrote: example query: /select distinct on (user_id) * from stories order by date_submitted desc limit 10;/ select user_id,max(date_submitted) from stories group by date_submitted; ? -- john r pierceN 37, W 122 santa cruz ca

Re: [GENERAL] Distinct on a non-sort column

2011-11-05 Thread Tom Lane
Cstdenis writes: > I am trying to write a query that selects recent submissions (sorted by > submission_date) but only selects the most recent one for each user_id. > example query: /select distinct on (user_id) * from stories order by > date_submitted desc limit 10;/ > However postgres will n

Re: [GENERAL] Distinct on a non-sort column

2011-11-05 Thread Tair Sabirgaliev
On Sun, Nov 6, 2011 at 12:39 AM, Cstdenis wrote: > I am trying to write a query that selects recent submissions (sorted by > submission_date) but only selects the most recent one for each user_id. > > example query: select distinct on (user_id) * from stories order by > date_submitted desc limit 1

[GENERAL] Distinct on a non-sort column

2011-11-05 Thread Cstdenis
I am trying to write a query that selects recent submissions (sorted by submission_date) but only selects the most recent one for each user_id. example query: /select distinct on (user_id) * from stories order by date_submitted desc limit 10;/ However postgres will not allow me to filter out