Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 077AC9FBED9 for ; Wed, 9 May 2007 15:03:21 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 68294-03-2 for ; Wed, 9 May 2007 15:03:06 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from exchange.g2switchworks.com (mail.g2switchworks.com [63.87.162.25]) by postgresql.org (Postfix) with ESMTP id 1FEA19FBF03 for ; Wed, 9 May 2007 15:03:07 -0300 (ADT) Received: from 10.10.1.37 ([10.10.1.37]) by exchange.g2switchworks.com ([10.10.1.2]) with Microsoft Exchange Server HTTP-DAV ; Wed, 9 May 2007 18:03:06 +0000 Received: from state.g2switchworks.com by mail.g2switchworks.com; 09 May 2007 13:03:06 -0500 Subject: Re: query to select a linked list From: Scott Marlowe To: Gregory Stark Cc: pgsql-sql@postgresql.org In-Reply-To: <878xbyi0zd.fsf@oxford.xeocode.com> References: <20070509125520.GA17497@apartia.fr> <878xbyi0zd.fsf@oxford.xeocode.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Message-Id: <1178733786.7497.57.camel@state.g2switchworks.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Wed, 09 May 2007 13:03:06 -0500 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/70 X-Sequence-Number: 28350 On Wed, 2007-05-09 at 08:24, 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. Are you sure the tablefunc functions, which include both connectby and crosstab functions, aren't up to date with 8.2? They certainly are up to 8.1, where I'm running them right now on my workstation. They built for 8.2 and installed, but I haven't tried using them. I would think that connectby is at least worth looking into.