| From: | "Ben K(dot)" <bkim(at)coe(dot)tamu(dot)edu> |
|---|---|
| To: | pgsql-sql(at)postgresql(dot)org |
| Cc: | Ray Madigan <ray(at)madigans(dot)org> |
| Subject: | Re: LinkedList |
| Date: | 2006-04-28 03:58:26 |
| Message-ID: | Pine.GSO.4.64.0604272249570.3093@coe.tamu.edu |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Penchalaiah P. | 2006-04-28 10:44:10 | set return function is returning a single record, multiple times, how can i get all the records in the table( description inside ) |
| Previous Message | Phillip Tornroth | 2006-04-27 21:06:14 | Multi-Column Constraints and Null Values |