[GENERAL] Recursive CTE trees + Sorting by votes

2014-08-06 Thread Gregory Taylor
We are working on a threaded comment system, and found this post by Disqus to be super helpful: http://cramer.io/2010/05/30/scaling-threaded-comments-on-django-at-disqus/ The CTE works wonderfully, and we're really happy with the results. The last obstacle is figuring out how to sort by a "votes"

Re: [GENERAL] Recursive CTE trees + Sorting by votes

2014-08-07 Thread Gregory Taylor
Hello Martijn, Thanks for the reply, my responses are inline below. On Wed, Aug 6, 2014 at 5:38 PM, Martijn van Oosterhout wrote: > On Wed, Aug 06, 2014 at 05:28:09PM -0400, Gregory Taylor wrote: > > We are working on a threaded comment system, and found this post by > Disqus >

Re: [GENERAL] Recursive CTE trees + Sorting by votes

2014-08-07 Thread Gregory Taylor
On Thu, Aug 7, 2014 at 8:12 AM, Vik Fearing wrote: > > Just export the order from your CTE. > > WITH RECURSIVE tree AS ( > SELECT dr.id, >..., >array[dr.id] as path, >1 as depth, >row_number() over (order by dr.num_votes desc) as sort_order >

Re: [GENERAL] Recursive CTE trees + Sorting by votes

2014-08-07 Thread Gregory Taylor
On Thu, Aug 7, 2014 at 11:57 AM, Paul Jungwirth wrote: > > Or another idea, add a column that is the path of the parent: > > I don't think this will work. The problem is you need the full path to > keep the children with their parents, but you also need the score. If > you make the path an array