Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 6F0E59FB59E for ; Wed, 9 May 2007 09:55:45 -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 02052-07 for ; Wed, 9 May 2007 09:55:33 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 64CDE9FB901 for ; Wed, 9 May 2007 09:55:37 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from sargon.lncsa.com (sargon.lncsa.com [212.99.8.251]) by svr4.postgresql.org (Postfix) with ESMTP id 247F55AF980 for ; Wed, 9 May 2007 12:55:36 +0000 (GMT) Received: from localhost (localhost [127.0.0.1]) by sargon.lncsa.com (Postfix) with ESMTP id 8E0E5146626A for ; Wed, 9 May 2007 14:55:27 +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 MOqZnwAxt7ZE for ; Wed, 9 May 2007 14:55:27 +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 29A2A146606B for ; Wed, 9 May 2007 14:55:27 +0200 (CEST) Received: from trajan.apartia.fr (trajan.apartia.fr [10.0.3.121]) by zenon.apartia.fr (Postfix) with ESMTP id 8DC3AF0A06B04 for ; Wed, 9 May 2007 14:55:23 +0200 (CEST) Received: by trajan.apartia.fr (Postfix, from userid 1000) id 865B125DDA74; Wed, 9 May 2007 14:55:20 +0200 (CEST) Date: Wed, 9 May 2007 14:55:20 +0200 From: Louis-David Mitterrand To: pgsql-sql@postgresql.org Subject: query to select a linked list Message-ID: <20070509125520.GA17497@apartia.fr> Mail-Followup-To: pgsql-sql@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.13 (2006-08-11) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200705/63 X-Sequence-Number: 28344 Hi, To build a threaded forum application I came up the following schema: forum ------ id_forum | integer| not null default nextval('forum_id_forum_seq'::regclass) id_parent| integer| subject | text | not null message | text | 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? Thanks,