Re: query to select a linked list

From: Scott Marlowe <smarlowe(at)g2switchworks(dot)com>
To: Aaron Bono <postgresql(at)aranya(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: query to select a linked list
Date: 2007-05-09 18:04:01
Message-ID: 1178733840.7497.59.camel@state.g2switchworks.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, 2007-05-09 at 08:29, Aaron Bono wrote:
> On 5/9/07, Louis-David Mitterrand <vindex+lists-pgsql-sql(at)apartia(dot)org>
> wrote:
> 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,
>
> Unlike Oracle, PostgreSQL doesn't have anything like a connect by so
> you would need to write your own stored procedure for that (if new
> versions of PostgreSQL will have connect by, let me know guys).

Take a look at the tablefunc in contrib, that seems to provide
connectby. I've only ever used the crosstab functions in there, but I
can't see what would have broken in connectby with 8.2 or anything.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Gregory Stark 2007-05-09 23:16:09 Re: query to select a linked list
Previous Message Scott Marlowe 2007-05-09 18:03:06 Re: query to select a linked list