From: | Gregory Taylor <gtaylor(at)gc-taylor(dot)com> |
---|---|
To: | Vik Fearing <vik(dot)fearing(at)dalibo(dot)com> |
Cc: | Martijn van Oosterhout <kleptog(at)svana(dot)org>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Recursive CTE trees + Sorting by votes |
Date: | 2014-08-07 12:29:52 |
Message-ID: | CAA0B==T3jVoDdiKN0Ow=CLT8sp1fu5eX68afbDCBpgpeHA+MXg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Thu, Aug 7, 2014 at 8:12 AM, Vik Fearing <vik(dot)fearing(at)dalibo(dot)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 sort_order
> FROM discussion_response AS dr
> WHERE dr.reply_parent_id IS NULL
> AND dr.discussion_id = 2763
>
> UNION ALL
>
> SELECT dr.id,
> ...,
> tree.path || dr.id,
> tree.depth + 1
> row_number() over (order by dr.num_votes desc)
> FROM discussion_response AS dr
> JOIN tree ON tree.id = dr.reply_parent_id
> WHERE NOT array[dr.id] <@ tree.path
> )
> SELECT *
> FROM tree
> ORDER BY depth, sort_order
> LIMIT 50;
>
It looks like this clobbers the hierarchy by sorting by depth first. I'm
trying to preserve said hierarchy so I can paginate using OFFSET/LIMIT
easily. I'm not sure what I'm shooting for is even possible, though.
--
Greg Taylor
http://gc-taylor.com
From | Date | Subject | |
---|---|---|---|
Next Message | Kevin Grittner | 2014-08-07 13:10:59 | Re: Reindex taking forever, and 99% CPU |
Previous Message | Vik Fearing | 2014-08-07 12:12:16 | Re: Recursive CTE trees + Sorting by votes |