Re: LinkedList - Mailing list pgsql-sql

From Scott Marlowe
Subject Re: LinkedList
Date
Msg-id 1146067158.23538.264.camel@state.g2switchworks.com
Whole thread Raw
In response to LinkedList  ("Ray Madigan" <ray@madigans.org>)
Responses Re: LinkedList  ("Ray Madigan" <ray@madigans.org>)
Re: LinkedList  ("Ben K." <bkim@coe.tamu.edu>)
List pgsql-sql
On Wed, 2006-04-26 at 11:09, Ray Madigan wrote:
> I have a table that I created that implements a linked list.  I am not an
> expert SQL developer and was wondering if there are known ways to traverse
> the linked lists.  Any information that can point me in the direction to
> figure this out would be appreciated.  The table contains many linked lists
> based upon the head of the list and I need to extract all of the nodes that
> make up a list.  The lists are simple with a item and a link to the history
> item so it goes kind of like:
> 
> 1, 0
> 3, 1
> 7, 3
> 9, 7
> ...
> 
> Any suggestions would be helpful, or I will have to implement the table
> differently.

You should be able to do this with a fairly simple self-join...

select a.id, b.aid, a.field1, b.field1 
from mytable a
join mytable b
on (a.id=b.aid)

Or something like that.


pgsql-sql by date:

Previous
From: "Ray Madigan"
Date:
Subject: LinkedList
Next
From: Tom Lane
Date:
Subject: Re: Migrating a Database to a new tablespace