Re: LinkedList - Mailing list pgsql-sql

From Ben K.
Subject Re: LinkedList
Date
Msg-id Pine.GSO.4.64.0604272249570.3093@coe.tamu.edu
Whole thread Raw
In response to Re: LinkedList  (Scott Marlowe <smarlowe@g2switchworks.com>)
Responses Re: LinkedList  (Guy Fraser <guy@incentre.net>)
List pgsql-sql
> 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


pgsql-sql by date:

Previous
From: Andreas Haumer
Date:
Subject: Re: Porting application with rules and triggers from PG 7.4.x
Next
From: "Penchalaiah P."
Date:
Subject: set return function is returning a single record, multiple times,how can i get all the records in the table( description inside )