Get A Tree from a table - Mailing list pgsql-sql

From gzscott2001@yahoo.ca (Scott Yaung)
Subject Get A Tree from a table
Date
Msg-id 341834e1.0210052137.7cbd6342@posting.google.com
Whole thread Raw
Responses Re: Get A Tree from a table
List pgsql-sql
I like to do something like this:(build a tree from relationship)
I have a table like this 

NODES__________________________________ParentID    Varchar(20)ParentType  varchar(20)ChildID     varchar(20)ChildType
varchar(20)

__________________________________
What in the table'A1', 'A', 'B1', 'B''A2', 'A', 'B2', 'B''A1', 'A', 'B3', 'B''B1', 'B', 'C1', 'C''B1', 'B', 'C2',
'C''C1','C', 'D1', 'D''A1', 'A', 'B4', 'B' 'B1', 'B', 'C5', 'C'
 

----------------------------------

now I like to get all nodes with 'A1' as root
to get the result like this'A1', 'A', 'B1', 'B''B1', 'B', 'C1', 'C''C1', 'C', 'D1', 'D''B1', 'B', 'C2', 'C''B1', 'B',
'C5','C''A1', 'A', 'B3', 'B''A1', 'A', 'B4', 'B' 
 

or I just like to get another tree start with 'B1'
like this'B1', 'B', 'C1', 'C''C1', 'C', 'D1', 'D''B1', 'B', 'C2', 'C''B1', 'B', 'C5', 'C'


How can i make it by sql , and sql functions
Thanks lot and regards.

Scott


pgsql-sql by date:

Previous
From: "Brian Ward"
Date:
Subject: timestamp
Next
From: "Brian Ward"
Date:
Subject: Re: timestamp