Re: Storing a tree - Mailing list pgsql-general

From Jochem van Dieten
Subject Re: Storing a tree
Date
Msg-id 3BEA8DF4.5020802@oli.tudelft.nl
Whole thread Raw
In response to Storing a tree  (Antonio Fiol Bonnín <fiol@w3ping.com>)
List pgsql-general
Antonio Fiol Bonnín wrote:

>
> I would like to store a tree in the database. A tree much like a
> directory tree, with un unknown depth.
>
> However, in my case, the order of the leafs (left to right) is
> important.
>
> I tried to implement the tree as a table:
>
> CREATE TABLE tree ( father_id int, son_id int );


There may be a better model for your data: the adjacency list model.
Take a look at http://www.intelligententerprise.com/001020/celko.shtml

If you want to implement it and you need/want to write stored procdures
and/or functions to do the most common list manipulation tasks we might
be able to work something out. I am a bit short of time at the moment,
but I believe it would be great if this stuff ended up in /contrib/ (or
is it there already?), and I am willing to invest time in that (but I am
leaving on holiday next week).

For more code, look at http://www.codebits.com/ntm/ (stored procedures
for using this model with MS SQL Server).

Jochem



pgsql-general by date:

Previous
From: jeff@muttworks.com (Jeff Young)
Date:
Subject: High Availability Cluster in Conjunction with PostGres
Next
From: "Richard Teviotdale"
Date:
Subject: Re: OID's as Primary Keys