I'm working on a reddit-like application that has comment trees, and am in the process of adding tree-paging: IE instead of returning the entire tree, I need to limit the number of results returned.
For example:
- The top level might have 15k replies.
- A deeply nested comment might have 2 replies.
- A simple SQL sort and limit will probably only contain the top level.
I need to create a postgres LIMIT query, that can limit the maximum # of children at any given level, to say 10 replies.
Is there any way to do this with ltrees, without doing queries for every single leaf?