Re: Ltree - how to sort nodes on parent node - Mailing list pgsql-general

From Alban Hertroys
Subject Re: Ltree - how to sort nodes on parent node
Date
Msg-id 1F96E061-713C-4929-A7D9-278E5B608EE1@solfertje.student.utwente.nl
Whole thread Raw
In response to Re: Ltree - how to sort nodes on parent node  (Harald Fuchs <hari.fuchs@gmail.com>)
List pgsql-general
On 20 Apr 2010, at 18:05, Harald Fuchs wrote:

> Here's a working version:
>
>  WITH RECURSIVE tree (path, category, sort_order, parent) AS (
>    SELECT category, category, sort_order::text, parent
>    FROM node
>    WHERE parent IS NULL
>  UNION ALL
>    SELECT t.path || '.' || n.category,
>           n.category,
>           t.sort_order || '.' || n.sort_order,
>           n.parent
>    FROM tree t
>    JOIN node n ON n.parent = t.category
>  )
>  SELECT path
>  FROM tree
>  ORDER BY sort_order


May be, but then you're just re-inventing ltree again. I'm pretty sure this must be possible without adding convoluted
thingslike casting sort orders to text (which can for example cause issues like '10' ending up between '1' and '2'). 

Since this is 8.4 anyway (CTE's after all), can't the sorting be done using a windowing function or something? We have
recursionnow, there's got to be a proper solution, I just can't get my mind around it right now. 

Alban Hertroys

--
If you can't see the forest for the trees,
cut the trees and you'll see there is no forest.


!DSPAM:737,4bcdf5a610412270627163!



pgsql-general by date:

Previous
From: Glus Xof
Date:
Subject: Specific database vars, again...
Next
From: Alban Hertroys
Date:
Subject: Re: Ltree - how to sort nodes on parent node