pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Scott Marlowe <smarlowe@g2switchworks.com>
To: Ray Madigan <ray@madigans.org>
Cc: pgsql-sql@postgresql.org
Subject: Re: LinkedList
Date: Wed, 26 Apr 2006 10:59:18 -0500
Message-ID: <1146067158.23538.264.camel@state.g2switchworks.com> (raw)
In-Reply-To: <IEELLOAPJFACBDBGELGHIEKMEDAA.ray@madigans.org>
References: <IEELLOAPJFACBDBGELGHIEKMEDAA.ray@madigans.org>

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.



view thread (10+ messages)  latest in thread

Message-ID: <1146067158.23538.264.camel@state.g2switchworks.com>
Permalink:  ../1146067158.23538.264.camel@state.g2switchworks.com/
Also on:    postgresql.org/message-id/1146067158.23538.264.camel@state.g2switchworks.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: smarlowe@g2switchworks.com, ray@madigans.org
  Subject: Re: LinkedList
  In-Reply-To: <1146067158.23538.264.camel@state.g2switchworks.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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