Re: Storing an ordered list - Mailing list pgsql-sql

From Aaron Bono
Subject Re: Storing an ordered list
Date
Msg-id bf05e51c0607281206r3f568c08v6c173232a1fbd1e8@mail.gmail.com
Whole thread Raw
In response to Re: Storing an ordered list  ("Michael Artz" <mlartz@gmail.com>)
List pgsql-sql
On 7/26/06, Michael Artz <mlartz@gmail.com> wrote:
On 7/26/06, Bruno Wolff III <bruno@wolff.to> wrote:
> If you use numeric instead of int, then it is easy to insert new values.

Hmm, hadn't thought about that.  How would you normally implement it?
I'm thinking that, if I wanted to insert between A and B, I could take
(A.order + B.order)/2, which would be pretty simple.  Is there a
better way?

 This is a good idea.  Then you can add a scheduled process to read through these values and turn them back to integer values on a regular basis (sort of a reindexing) to keep your numbers from becoming small enough that you start experiencing round off problems.  Perhaps you could add a trigger that says if the value entered into the order field is going out to too many decimal places, it renumbers everything. to keep the values clean.  Or better yet, add a stored procedure you call to reorder the elements that decides how to do it for you so you can easily rewrite the implementation without having to change the application.

Just some ideas...

==================================================================
   Aaron Bono
   Aranya Software Technologies, Inc.
   http://www.aranya.com
==================================================================

pgsql-sql by date:

Previous
From: "Chris Lukenbill"
Date:
Subject: Re: return setof records
Next
From: "Aaron Bono"
Date:
Subject: Re: primary keys as TEXT