From jkanter@virginia.edu Fri Jun 13 18:56:20 2003 X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id B191E30D6D2 for ; Fri, 13 Jun 2003 18:56:20 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 89198-01 for ; Fri, 13 Jun 2003 15:56:09 -0300 (ADT) Received: from mail.virginia.edu (mail.Virginia.EDU [128.143.2.9]) by svr1.postgresql.org (Postfix) with SMTP id C8CE430D191 for ; Fri, 13 Jun 2003 15:56:06 -0300 (ADT) Received: from smtp.mail.virginia.edu by mail.virginia.edu id aa19567; 13 Jun 2003 14:56 EDT Received: from virginia.edu (d-128-19-222.bootp.Virginia.EDU [128.143.19.222]) by smtp.mail.Virginia.EDU (8.11.7/8.11.6) with ESMTP id h5DIqXl22642 for ; Fri, 13 Jun 2003 14:52:33 -0400 Message-ID: <3EEA1F57.1070002@virginia.edu> Date: Fri, 13 Jun 2003 15:00:39 -0400 From: Jodi Kanter User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:0.9.4) Gecko/20011128 Netscape6/6.2.1 X-Accept-Language: en-us MIME-Version: 1.0 To: Postgres Admin List Subject: list ranking Content-Type: multipart/alternative; boundary="------------080307010400070500000904" X-Archive-Number: 200306/144 X-Sequence-Number: 9135 --------------080307010400070500000904 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit We have a set of records in a table that needs to be ranked. We thought of adding a ranking field, but the problem is that the ranking could change often and there could be additions and deletions from the list. Updating this ranking field is quickly going to get messy. Is anyone familiar with link surgery? Can we do this with a doubly linked list? Is there a standard database solution for doubly linked lists? or another way to solve this that I don't see? Any suggestions on structure would be greatly appreciated. Thanks Jodi -- _______________________________ Jodi L Kanter BioInformatics Database Administrator University of Virginia (434) 924-2846 jkanter@virginia.edu --------------080307010400070500000904 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit We have a set of records in a table that needs to be ranked. We thought of adding a ranking field, but the problem is that the ranking could change often and there could be additions and deletions from the list. Updating this ranking field is quickly going to get messy.

Is anyone familiar with link surgery? Can we do this with a doubly linked list? Is there a standard database solution for doubly linked lists? or another way to solve this that I don't see?
Any suggestions on structure would be greatly appreciated.

Thanks
Jodi
--
________________________________

_______________________________
Jodi L Kanter
BioInformatics Database Administrator
University of Virginia
(434) 924-2846
jkanter@virginia.edu


 

 

 

--------------080307010400070500000904-- From mail@joeconway.com Sat Jun 14 05:36:31 2003 X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id C83B630E60D for ; Sat, 14 Jun 2003 05:36:31 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 56975-06 for ; Sat, 14 Jun 2003 02:36:21 -0300 (ADT) Received: from joeconway.com (66-146-172-86.skyriver.net [66.146.172.86]) by svr1.postgresql.org (Postfix) with ESMTP id 9A75D30E60B for ; Sat, 14 Jun 2003 02:36:20 -0300 (ADT) Received: from [192.168.5.3] (account jconway HELO joeconway.com) by joeconway.com (CommuniGate Pro SMTP 4.0.6) with ESMTP-TLS id 1804122; Fri, 13 Jun 2003 22:10:50 -0700 Message-ID: <3EEAB3E2.7000508@joeconway.com> Date: Fri, 13 Jun 2003 22:34:26 -0700 From: Joe Conway User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Jodi Kanter Cc: Postgres Admin List Subject: Re: list ranking References: <3EEA1F57.1070002@virginia.edu> In-Reply-To: <3EEA1F57.1070002@virginia.edu> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Archive-Number: 200306/148 X-Sequence-Number: 9139 Jodi Kanter wrote: > We have a set of records in a table that needs to be ranked. We thought > of adding a ranking field, but the problem is that the ranking could > change often and there could be additions and deletions from the list. > Updating this ranking field is quickly going to get messy. > > Is anyone familiar with link surgery? Can we do this with a doubly > linked list? Is there a standard database solution for doubly linked > lists? or another way to solve this that I don't see? > Any suggestions on structure would be greatly appreciated. It sounds to me like you just need a way to enforce a sort order that is able to handle insertions into the middle of the list? What about something like this: create table foo(f1 int, f2 text); create unique index foo_idx1 on foo(f2); insert into foo values(1,'0000'); insert into foo values(2,'0001'); -- -- insert new values in between '0000' and '0001' insert into foo values(3,'0000.0000'); insert into foo values(4,'0000.0001'); -- -- we happen to need one right between those last two insert into foo values(5,'0000.0000.0000'); -- -- now get them back in rank order regression=# select * from foo order by f2; f1 | f2 ----+---------------- 1 | 0000 3 | 0000.0000 5 | 0000.0000.0000 4 | 0000.0001 2 | 0001 (5 rows) You might want to periodically run a maintenance script that collapses the segments (i.e. turn f2 above into '0000', '0001', '0002', '0003', and '0004'). HTH, Joe