View Single Post
  #1 (permalink)  
Old 10-29-09, 12:24
tjakobsen tjakobsen is offline
Registered User
 
Join Date: Mar 2009
Posts: 2
Inserting into a hierachy (nested set model)

Hello,

I have a hierachy of groups modelled as a nested set. Like Joe Celko does it in his book "Trees and hierachies in SQL for smarties".

I have a problem creating a query that will insert a new node at the rightmost position under a given parent node.

If I have the tree:

Code:
           node1
       /     |     \
     /       |       \
   /         |         \
node2      node3     node4
  |
node5
I want to insert a new node6 here:

Code:
           node1   
         
     /    |     |   \
    /     |     |    \        
   /      |     |     \
node2   node3  node4  node6
   |
node5
In Celkos book, he gives a procedure that would add the new node, given the parent node (node1), as a sibling to node4. And another procedure that would add the new node to the right of a given sibling (node4). That approach is close to what I need, but I need to add it using the parent node.

Anyone who has a procedure that can help me do that?

Thanks in advance!
Reply With Quote