Re: Trees in SQL - Mailing list pgsql-sql

From Josh Berkus
Subject Re: Trees in SQL
Date
Msg-id 200205271306.53646.josh@agliodbs.com
Whole thread Raw
In response to Trees in SQL  (Gregory Brauer <greg@wildbrain.com>)
List pgsql-sql
Greg,

> What sort of strategies are best for storing tree structures in a
> relational database, and how would one structure SQL queries to find,
> say, "all of the children anywhere under this node", or to represent
> the condition "if this node is a child at any depth under this other
> node"?  Are there good strategies for preventing cycles?

Joe Celko covers this extensively in his book "SQL for Smarties."  You should
definitely buy it and read the two chapters on tree structures before going
any further.

I will be writing an article for Techdocs within the month on implementing
Celko's "Linear Nested Sets Model" of trees in PostgreSQL.  If you can't
wait, buy the book, e-mail me, and I'll send you my notes.

--
-Josh Berkus





pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Creation of a table with dynamic name from inside a pgpsql function
Next
From: "Beth Gatewood"
Date:
Subject: query system tables to find columns unique constraint is constraining?