[GENERAL] Query to select nested comments sorted by nesting and date

2011-06-23 Thread Cstdenis
I am trying to select nested comments from a table with this structure CREATE TABLE picture_comments ( comment_id serial NOT NULL, user_id integer NOT NULL, "comment" text NOT NULL DEFAULT ''::text, comment_date timestamp without time zone NOT NULL DEFAULT now(),

[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

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-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