pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ben K. <bkim@coe.tamu.edu>
To: pgsql-sql@postgresql.org
Cc: Ray Madigan <ray@madigans.org>
Subject: Re: LinkedList
Date: Thu, 27 Apr 2006 22:58:26 -0500 (CDT)
Message-ID: <Pine.GSO.4.64.0604272249570.3093@coe.tamu.edu> (raw)
In-Reply-To: <1146067158.23538.264.camel@state.g2switchworks.com>
References: <IEELLOAPJFACBDBGELGHIEKMEDAA.ray@madigans.org>
	<1146067158.23538.264.camel@state.g2switchworks.com>

> 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:

It may not be exactly suitable, but this one does only traversal (assuming 
the list is not clsoed)

create table linkedlist(prevnode int, nextnode int, val int);
-- HEAD
insert into linkedlist values(null,1,0);
insert into linkedlist values(1,2,10);
insert into linkedlist values(2,3,20);
insert into linkedlist values(3,4,30);
insert into linkedlist values(4,5,40);
-- TAIL
insert into linkedlist values(5,null,50);

-- TRAVERSE
begin;
declare mc cursor for select * from linkedlist order by nextnode;
fetch 1 from mc;
fetch 1 from mc;
...
close mc;
commit;

which is nothing more than,
select * from linkedlist order by nextnode;


Regards,

Ben K.
Developer
http://benix.tamu.edu



view thread (10+ messages)  latest in thread

Message-ID: <Pine.GSO.4.64.0604272249570.3093@coe.tamu.edu>
Permalink:  ../Pine.GSO.4.64.0604272249570.3093@coe.tamu.edu/
Also on:    postgresql.org/message-id/Pine.GSO.4.64.0604272249570.3093@coe.tamu.edu

 · 

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: bkim@coe.tamu.edu, ray@madigans.org
  Subject: Re: LinkedList
  In-Reply-To: <Pine.GSO.4.64.0604272249570.3093@coe.tamu.edu>

* 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