Hierarchical queries - Mailing list pgsql-general

From Anton.Nikiforov@loteco.ru
Subject Hierarchical queries
Date
Msg-id 16314523754.20040109220506@loteco.ru
Whole thread Raw
Responses Re: Hierarchical queries  (Andrew Rawnsley <ronz@ravensfield.com>)
Re: Hierarchical queries  (Oleg Bartunov <oleg@sai.msu.su>)
Re: Hierarchical queries  (Anton.Nikiforov@loteco.ru)
List pgsql-general
Hello everybody!

Does someone know how to build hierarchical queries to the postgresql?

I have a table with tree in it (id, parent)
and need to find a way from any point of the tree to any other point.
And i would like to have a list of all steps from point A to point B
to make some changes on each step (this is required by the algorythm).

Here is an example:
treetable (where tree is stored):
id        parent   data
int4      int4     varchar(255)
0         0        root
1         0        root's chield 1
2         0        root's chield 2
3         1        root's chield 1 chield 1
4         1        root's chield 1 chield 2
5         2        root's chield 2 chield 1
6         2        root's chield 2 chield 2

And i want to get something like this:
start point "root's chield 2 chield 2"
finish "root's chield 1 chield 1"

And the result i need:
id        parent   data
6         2        root's chield 2 chield 2
2         0        root's chield 2
0         0        root
1         0        root's chield 1
4         1        root's chield 1 chield 2

i know that it is possible in Oracle but what about postgres?

Best regards,
Anton Nikiforov


pgsql-general by date:

Previous
From: Teodor Sigaev
Date:
Subject: Re: TSearch2 ... ignore word repetition for rank
Next
From: Andrew Rawnsley
Date:
Subject: Re: Hierarchical queries