Re: Hierarchical queries

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

Hello Oleg!
There is no data yet, i'm just planning to start a new project :)
Text labels are just fine and i red the documentation from the top to
the very end a few times and found the way to use your module, but
using it will not as beautiful as i was planning mathematicaly.
You know i have (planning to have) a tree like:
>> >> 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 to find a way from the record with id #6 to the record with id #3
WITH YOUR MODULE:
I have to find Lowest Common Ancestor (lca)
Then to find a path from id #6 to lca
Then to find a path from lca to id#3
Then combine this pathes (remember that i need all steps from id #6 to
id #3)
And then run a special code to update all needed data (create records
in different tables)

IN MY BRAINS:
I just need to have function that will rotate a tree and make id #6
the root element and then select a path from root (id#6) to desired id
#3. As i think somebody did this already. And i'm not the first who is
trying to find out the code.

If i'm too stupid to understand the ability of your module - just give
me a direction (i did installed your module and currently playing with
it, so maybe my stupidity will become wiser and wiser in the nearest
feature) :))))

Best regards,
Anton
OB> 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?

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

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

OB> 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
>>

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

С уважением,
IT Директор ООО "Лотэко"
Антон Никифоров
Тел.: +7 095 7814200
Факс: +7 095 7814201
Mail: Anton(dot)Nikiforov(at)loteco(dot)ru
Web: www.loteco.ru

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joe Conway 2004-01-10 17:57:14 Re: Hierarchical queries
Previous Message Oleg Bartunov 2004-01-10 16:36:56 Re: Hierarchical queries