X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id D68A79FABE7 for ; Tue, 25 Jul 2006 23:58:59 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 46776-05 for ; Tue, 25 Jul 2006 23:58:50 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.188]) by postgresql.org (Postfix) with ESMTP id AADEE9FA68D for ; Tue, 25 Jul 2006 23:58:49 -0300 (ADT) Received: by nf-out-0910.google.com with SMTP id p77so458909nfc for ; Tue, 25 Jul 2006 19:58:47 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=LMyD65BO8trq/ls5O4nHJJC5UOvcPgejqO46/0Isz8HSapeZfo1gOpnnDPUqQq2sSrw8KVvAO7OxntJ/OH5WXMZZwHvP+eMlojz5cbWnRGGCUITwT2HzmPVnRgz+2Y/+l95Ccn/t8K+ARCXrZTEdcE2COKwXgxsbWoUg6s/mkWM= Received: by 10.78.165.16 with SMTP id n16mr2784959hue; Tue, 25 Jul 2006 19:58:47 -0700 (PDT) Received: by 10.78.153.11 with HTTP; Tue, 25 Jul 2006 19:58:47 -0700 (PDT) Message-ID: Date: Tue, 25 Jul 2006 22:58:47 -0400 From: "Michael Artz" To: pgsql-sql@postgresql.org Subject: Storing an ordered list MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.199 tagged_above=0 required=5 tests=DNS_FROM_RFC_ABUSE, SPF_PASS X-Spam-Level: X-Archive-Number: 200607/314 X-Sequence-Number: 25888 What is the best way to store and ordered list that can be updated OLTP-style? A simplified problem is that I have an event, and the event has an ordered list of predicates and I need to preserve the order of the predicates. All of the data is entered via a web application, and I would like to support the new flashy ajax drag-droppy thingies, meaning that there could be a significant amount of updates if the user is dragging things all over the place. I figure that one choice is to explicitly code the order as an integer column in the predicate table which has the advantage of being very easy and fast to query/order but *very* slow to reorder as all of the predicates need to be updated. This would seem to be a postgres/MVCC weak spot as well. Example: create table event (event_id integer); create table predicate (event_id integer not null references event(event_id), name varchar, order integer); insert into event (event_id) values (1); insert into predicate (1, 'first event', 1); insert into predicate (1, 'second predicate', 2); select * from predicate p where p.event_id = 1 order by p.order; I'm also thinking about a linked list, i.e. create table event (event_id integer); create table predicate (predicate_id integer, event_id integer not null references event(event_id), name varchar, next_predicate integer references predicate (predicate_id)); insert into predicate (101, 1, 'second predicate', NULL); insert into predicate (102, 1, 'first predicate', 101); The downside is that I'm not quite sure how to efficiently query the linked list. Any suggestions? Are there any known best practices for storing ordered lists in relational databases? Are there any tricks that I can use with postgres? Thanks -Mike