Hi, it's me again.
I thought about that branch as array thing.
What would yout think about a function that ascends a tree from a given
node to the topmost and returns the path as a table ?
Implementing the array n connectby is fine, but as I don't like arrays
too much :) maybe there should be a dedicated reverselookup, too.
If someone is only interested in the path to 1 node, this function could
be handier and possibly faster.
Am Sam, 2003-06-21 um 06.20 schrieb Joe Conway:
> In 7.4 there may be a slightly better workaround (if a submitted patch
> gets accepted). You can convert branch into an array of integers, and
> order by that:
>
> select ss.id_nav, ss.id2_nav, ss.level,
> string_to_array(ss.branch,'~')::int[] as branch, n.nav,n.pos from nav n,
> (select id_nav,id2_nav,level,branch from
> connectby('nav','id_nav','id2_nav','1',0,'~') as (id_nav int, id2_nav
> int, level int, branch text)) as ss where n.id_nav = ss.id_nav order by
> string_to_array(ss.branch,'~')::int[];
> id_nav | id2_nav | level | branch | nav | pos
> --------+---------+-------+----------+---------+-----
> 1 | | 0 | {1} | World | 0
> 2 | 1 | 1 | {1,2} | Top | 1
> 5 | 2 | 2 | {1,2,5} | Home | 0
> 6 | 2 | 2 | {1,2,6} | News | 1
> 3 | 1 | 1 | {1,3} | Left | 2
> 4 | 1 | 1 | {1,4} | Support | 0
> 7 | 4 | 2 | {1,4,7} | Contact | 0
> 8 | 4 | 2 | {1,4,8} | Search | 1
> 9 | 4 | 2 | {1,4,9} | Sitemap | 2
> 10 | 4 | 2 | {1,4,10} | Imprint | 3
> (10 rows)
--
e-Trolley Sayegh & John, Nabil Sayegh
Tel.: 0700 etrolley /// 0700 38765539
Fax.: +49 69 8299381-8
PGP : http://www.e-trolley.de