pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedChain/Thread Problem
3+ messages / 3 participants
[nested] [flat]
* Chain/Thread Problem
@ 2003-05-16 14:46 Sammy <sammynash@uboot.com>
0 siblings, 2 replies; 3+ messages in thread
From: sammynash@uboot.com @ 2003-05-16 14:46 UTC (permalink / raw)
To: pgsql-sql
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)
ie
a sucessulf qurey would return rows 1,2 & n because they are all in
the chain.
Hope you can help me with my problem,
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Chain/Thread Problem
@ 2003-05-16 16:53 J Sensel <jsensel ateggheadsdotcom@news.hub.org>
parent: Sammy <sammynash@uboot.com>
1 sibling, 0 replies; 3+ messages in thread
From: J Sensel @ 2003-05-16 16:53 UTC (permalink / raw)
To: pgsql-sql
Sammy..
A quick and dirty approach is something like this:
id|threadid|emailid|referenceid|pathlevel
---------------------------------------
1|t101|e323|null|0
2|t101|e545|e323|1
3|t101|e822|e545|2
4|t101|e999|e323|1
etc..
Do the sorting when you insert the records. Then they can be quickly &
easily retrieved. Otherwise you're looking at a recursive query. Not very
efficient. This way is crude but allows the engine to optimize queries with
indexes.
HTH
Jim
"Sammy" <sammynash@uboot.com> wrote in message
news:6729af8d.0305160646.d9ab2d2@posting.google.com...
> 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)
>
> ie
> a sucessulf qurey would return rows 1,2 & n because they are all in
> the chain.
>
> Hope you can help me with my problem,
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Chain/Thread Problem
@ 2003-05-16 17:22 Richard Huxton <dev@archonet.com>
parent: Sammy <sammynash@uboot.com>
1 sibling, 0 replies; 3+ messages in thread
From: Richard Huxton @ 2003-05-16 17:22 UTC (permalink / raw)
To: sammynash@uboot.com; 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
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2003-05-16 17:22 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-05-16 14:46 Chain/Thread Problem Sammy <sammynash@uboot.com>
2003-05-16 16:53 ` J Sensel <jsensel ateggheadsdotcom@news.hub.org>
2003-05-16 17:22 ` Richard Huxton <dev@archonet.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox