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