Skip site navigation (1) Skip section navigation (2)

Processing Tables containing tree-like data

From: psql-novice(at)netzach(dot)co(dot)il
To: pgsql-novice(at)postgresql(dot)org
Subject: Processing Tables containing tree-like data
Date: 2007-05-29 16:58:11
Message-ID: Pine.LNX.4.58.0705291945470.6674@perpetual.homelinux.org (view raw or flat)
Thread:
Lists: pgsql-novice
Hi,

I have a table which looks like this:

id	info	parentid
0	<God>	0
1	Adam	0
2	Cain	1
3	Abel	1
4	Seth	1
5	Enosh	4
....



I am looking for a fast and efficient way of finding ALL the descendents
of any particular node, to unlimited depth.

Is there a standard database trick for doing this efficiently ? Writing
a recursive function would be extremely inefficient for repeated
queries.

Thanks,


Netzach

Responses

pgsql-novice by date

Next:From: Richard Broersma JrDate: 2007-05-29 17:39:44
Subject: Re: Processing Tables containing tree-like data
Previous:From: JoshuaDate: 2007-05-29 16:43:45
Subject: Re: problems with SELECT query results

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group