Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 1F2789FB599 for ; Wed, 9 May 2007 10:29:09 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 27383-03-7 for ; Wed, 9 May 2007 10:28:59 -0300 (ADT) X-Greylist: delayed 00:33:34.013507 by SQLgrey-1.7.5 Received: from sargon.lncsa.com (sargon.lncsa.com [212.99.8.251]) by postgresql.org (Postfix) with ESMTP id 77C799FB4D1 for ; Wed, 9 May 2007 10:29:04 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by sargon.lncsa.com (Postfix) with ESMTP id 798E5142290B for ; Wed, 9 May 2007 15:29:02 +0200 (CEST) Received: from sargon.lncsa.com ([127.0.0.1]) by localhost (sargon.lncsa.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gYwaiYE0dPAU for ; Wed, 9 May 2007 15:29:02 +0200 (CEST) Received: from zenon.apartia.fr (zenon.apartia.fr [10.0.3.1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "zenon.apartia.fr", Issuer "ca.apartia.fr" (verified OK)) by sargon.lncsa.com (Postfix) with ESMTP id 3733C1424BBA for ; Wed, 9 May 2007 15:29:02 +0200 (CEST) Received: from trajan.apartia.fr (trajan.apartia.fr [10.0.3.121]) by zenon.apartia.fr (Postfix) with ESMTP id 03BDCF0A06B04 for ; Wed, 9 May 2007 15:29:01 +0200 (CEST) Received: by trajan.apartia.fr (Postfix, from userid 1000) id EDAFE2C10D48; Wed, 9 May 2007 15:28:57 +0200 (CEST) Date: Wed, 9 May 2007 15:28:57 +0200 From: Louis-David Mitterrand To: pgsql-sql@postgresql.org Subject: Re: query to select a linked list Message-ID: <20070509132857.GA18313@apartia.fr> Mail-Followup-To: pgsql-sql@postgresql.org References: <20070509125520.GA17497@apartia.fr> <878xbyi0zd.fsf@oxford.xeocode.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <878xbyi0zd.fsf@oxford.xeocode.com> User-Agent: Mutt/1.5.13 (2006-08-11) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/65 X-Sequence-Number: 28346 On Wed, May 09, 2007 at 02:24:22PM +0100, Gregory Stark wrote: > "Louis-David Mitterrand" writes: > > > Each message a unique id_forum and an id_parent pointing to the replied > > post (empty if first post). > > > > How can I build an elegant query to select all messages in a thread? > > You would need recursive queries which Postgres doesn't support. There is a > patch out there to add support but I don't think it's up-to-date with 8.2 and > in any case the resulting queries can be quite intense. > > I would recommend you look into the contrib module named "ltree". It's easy to > use and works well with the gist indexes. It does require changing your data > model denormalizing it slightly which makes it hard to "reparent" children, > but if that isn't an operation you have to support I think it makes most other > operations you might want to do much easier to support. After looking around a little I came to the same conclusions. Thanks for you help, Cheers,