Re: Trees in SQL

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Gregory Brauer <greg(at)wildbrain(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Trees in SQL
Date: 2002-05-27 20:06:53
Message-ID: 200205271306.53646.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Stef Telford 2002-05-27 22:46:50 Triggers and System Tables.
Previous Message Tom Lane 2002-05-27 20:06:10 Re: Some additional PostgreSQL questions