Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: LinkedList



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.



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group