Re: Hierarchical queries

From: Oleg Bartunov <oleg(at)sai(dot)msu(dot)su>
To: Anton(dot)Nikiforov(at)loteco(dot)ru
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Hierarchical queries
Date: 2004-01-10 16:36:56
Message-ID: Pine.GSO.4.58.0401101930420.26836@ra.sai.msu.su
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, 10 Jan 2004 Anton(dot)Nikiforov(at)loteco(dot)ru wrote:

> Hello Oleg and thanks for the link, but i could not understand how to
> get path from one point of the tree to another?

have you read documentation ? Get all childrens - ltree <@ ltree,
for example:

ltreetest=# select path from test where path <@ 'Top.Science';
path
------------------------------------
Top.Science
Top.Science.Astronomy
Top.Science.Astronomy.Astrophysics
Top.Science.Astronomy.Cosmology
(4 rows)

You should provide us example of your data and query, so we could help you.

> Anyway thanks :)
>
> Best regards,
> Anton
> OB> Look at contrib/ltree
> OB> http://www.sai.msu.su/~megera/postgres/gist/ltree
>
> OB> Oleg
> OB> On Fri, 9 Jan 2004 Anton(dot)Nikiforov(at)loteco(dot)ru wrote:
>
> >> 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
> >>
> >>
> >> ---------------------------(end of broadcast)---------------------------
> >> TIP 7: don't forget to increase your free space map settings
> >>
>
> OB> Regards,
> OB> Oleg
> OB> _____________________________________________________________
> OB> Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
> OB> Sternberg Astronomical Institute, Moscow University (Russia)
> OB> Internet: oleg(at)sai(dot)msu(dot)su, http://www.sai.msu.su/~megera/
> OB> phone: +007(095)939-16-83, +007(095)939-23-83
>
> OB> ---------------------------(end of broadcast)---------------------------
> OB> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>

Regards,
Oleg
_____________________________________________________________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: oleg(at)sai(dot)msu(dot)su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Anton.Nikiforov 2004-01-10 17:02:48 Re: Hierarchical queries
Previous Message Dennis Björklund 2004-01-10 16:27:21 Re: psql \d option list overloaded