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 klep...@svana.org 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 to

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

2014-08-07 Thread Vik Fearing
On 08/07/2014 01:22 PM, Gregory Taylor wrote: I got this recommendation from someone else, and think that it's probably the way to go. I've been playing with it unsuccessfully so far, though. Most certainly because I've got something weirded up. Here's what I have: WITH RECURSIVE cte

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 vik.fear...@dalibo.com 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

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

2014-08-07 Thread Paul Jungwirth
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 of (-votes, id) tuples (perhaps flattened for simplicity), then

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 p...@illuminatedcomputing.com 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

[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-06 Thread Martijn van Oosterhout
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 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