Received: from akirason.se.verio.net (akirason.se.verio.net [204.27.64.122]) by postgresql.org (8.11.3/8.11.4) with ESMTP id f8LIkge39259 for ; Fri, 21 Sep 2001 14:46:42 -0400 (EDT) (envelope-from jeckermann@verio.net) Received: from beancounter (no-wkstns.gs.verio.net [204.27.67.225]) (authenticated) by akirason.se.verio.net (8.11.4/8.11.4) with ESMTP id f8LIprI37585; Fri, 21 Sep 2001 13:51:53 -0500 (CDT) (envelope-from jeckermann@verio.net) Message-ID: <02f301c142cd$bd6bebe0$279c10ac@INTERNAL> From: "Jeff Eckermann" To: "Juan Jose Comellas" , References: <200109211614.f8LGEZk21143@mens.hq.novamens.com> Subject: Re: Recursive queries Date: Fri, 21 Sep 2001 13:46:35 -0500 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: 200109/701 X-Sequence-Number: 15450 There was a detailed post by Joe Celko not long ago, which discussed how to handle trees in SQL. I suggest you look at the list archives to find this. ----- Original Message ----- From: "Juan Jose Comellas" To: Sent: Friday, September 21, 2001 11:14 AM Subject: [GENERAL] Recursive queries > I have a database with the following fields: > > product_id INTEGER > parent_id INTEGER > name VARCHAR(64) > > The idea is that it will store a tree of products and its subproducts. Any > row whose parent_id is NULL will be assumed to be a root product (i.e. top > level). > > This means I will need to process recursively, with some sort of reference to > parent_id passing through layers of recursion. > > However, I want to save on database queries and do a "SELECT *", then fetch > each row on the results recursively, to build the tree. The idea is to only > have to do one db query. > > Does anyone have any idea how this can be done in PostgreSQL? Both Oracle and > DB2 support this with their own proprietary syntax. > > > -- > Juan Jose Comellas > (juanjo@comellas.org) > > ---------------------------(end of broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) > >