Re: Storing a tree

From: Jochem van Dieten <jochemd(at)oli(dot)tudelft(dot)nl>
To: Antonio Fiol Bonnín <fiol(at)w3ping(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Storing a tree
Date: 2001-11-08 13:51:48
Message-ID: 3BEA8DF4.5020802@oli.tudelft.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-jdbc

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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-11-08 13:59:18 Re: pg_dump usage - problems with restore due to the use of tab delimiters
Previous Message Jeff Young 2001-11-08 13:26:58 High Availability Cluster in Conjunction with PostGres

Browse pgsql-jdbc by date

  From Date Subject
Next Message Nick Fankhauser 2001-11-08 13:59:21 Re: Connection and Statement
Previous Message Erwin Ambrosch 2001-11-08 13:02:39 Connection and Statement