Re: Chain/Thread Problem - Mailing list pgsql-sql

From Richard Huxton
Subject Re: Chain/Thread Problem
Date
Msg-id 200305161822.37391.dev@archonet.com
Whole thread Raw
In response to Chain/Thread Problem  (sammynash@uboot.com (Sammy))
List pgsql-sql
On Friday 16 May 2003 3:46 pm, Sammy wrote:
> Hi,
>
> I have a SQL problem for you all. What SQL qurey would I have to make
> on the following table to extract the chain (thread) of emails in a
> conversation.
>
>
>          id|emailid|referenceid
>          -----------------------
>           1|  e125 |   Null             (Start of chain)
>           2|  r1fe |   e125             (2nd letter in chain)
>           ...
>           ...
>           n|  e4ju |   r1fe             (3rd in chain)

Search the archives for "connect by", "hierarchy", "nested" and "celko" - this
is a limitation of SQL. In your particular case, I'd add a SERIAL "thread_id"
column which is autogenerated for the first msg in a thread and set to the
first message for all others.

You might want to check the contrib/ directory, I've got a feeling there's an
example table-function to do something like this.
--  Richard Huxton


pgsql-sql by date:

Previous
From: "J Sensel"
Date:
Subject: Re: Chain/Thread Problem
Next
From: Richard Huxton
Date:
Subject: Re: Efficiency Issue with "SELECT IN (..)" and "SELECT .. OR .."