Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id DB9424761F2 for ; Fri, 24 May 2002 20:07:32 -0400 (EDT) Received: from kennedy.calorieking.com (adsl-64-164-82-57.dsl.lsan03.pacbell.net [64.164.82.57]) by postgresql.org (Postfix) with ESMTP id 823A84763E1 for ; Fri, 24 May 2002 20:04:45 -0400 (EDT) Received: from Allan ([192.168.0.50]) by kennedy.calorieking.com (8.11.6/8.11.6) with SMTP id g4OH2RL01943; Fri, 24 May 2002 17:02:27 GMT (envelope-from chriskl@familyhealth.com.au) Message-ID: <011501c2037f$ad4b5340$9865fea9@Allan> From: "Christopher Kings-Lynne" To: "Gregory Brauer" , References: <3CEE818B.9020702@wildbrain.com> Subject: Re: Trees in SQL Date: Fri, 24 May 2002 17:04:01 -0700 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Archive-Number: 200205/271 X-Sequence-Number: 7906 Try here maybe: http://cddb.sai.msu.su/~megera/postgres/gist/ Look at their new 'tree' module... Chris ----- Original Message ----- From: "Gregory Brauer" To: Sent: Friday, May 24, 2002 11:08 AM Subject: [SQL] Trees in SQL > > I hope this isn't an overly broad topic that ends up diverging into graph > theory, but I have a tree structure of identical items (analogous to a > filesystem directory tree) that I need to store in Postgres. The > "obvious" design is to give the table that will represent these objects > a field identifying its "parent" that is a relation to the same table. > However, this seems to make many common SQL queries rather difficult. > > 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? > > I'd appreciate any insights anyone can give. > > Thanks. > > Greg Brauer > greg@wildbrain.com > > > ---------------------------(end of broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/users-lounge/docs/faq.html >