Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 8AAC7475B3E for ; Tue, 28 May 2002 14:14:03 -0400 (EDT) Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (Postfix) with ESMTP id 92E96475A89 for ; Tue, 28 May 2002 14:14:02 -0400 (EDT) Received: from [66.219.92.2] (HELO chocolate-mousse) by davinci.ethosmedia.com (CommuniGate Pro SMTP 3.5.9) with ESMTP id 1491997; Tue, 28 May 2002 11:14:01 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: Gregory Brauer , pgsql-sql@postgresql.org Subject: Re: Trees in SQL Date: Mon, 27 May 2002 13:06:53 -0700 X-Mailer: KMail [version 1.4] References: <3CEE818B.9020702@wildbrain.com> In-Reply-To: <3CEE818B.9020702@wildbrain.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200205271306.53646.josh@agliodbs.com> X-Archive-Number: 200205/298 X-Sequence-Number: 7933 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 shou= ld=20 definitely buy it and read the two chapters on tree structures before going= =20 any further. I will be writing an article for Techdocs within the month on implementing= =20 Celko's "Linear Nested Sets Model" of trees in PostgreSQL. If you can't=20 wait, buy the book, e-mail me, and I'll send you my notes. --=20 -Josh Berkus