Re: Storing an ordered list

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Michael Artz <mlartz(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Storing an ordered list
Date: 2006-07-27 13:18:23
Message-ID: 20060727131823.GA30179@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, Jul 26, 2006 at 20:13:03 -0400,
Michael Artz <mlartz(at)gmail(dot)com> wrote:
> On 7/26/06, Bruno Wolff III <bruno(at)wolff(dot)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?

I think that will depend. To keep the size of the number down, you will
probably want to use the number with the fewest digits to the right of the
decimal point that gives you a number between the two values. That will be
a bit more complicated than the above formula. But you will want to do
something to keep the size of the numerics down since it seems like reordering
will be common.

Another issue to consider is concurrency. You may want to lock the table
against concurrent reordering, as doing two at once may lead to some unexpected
events.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Daniel Caune 2006-07-27 16:00:47 PostgreSQL server terminated by signal 11
Previous Message Michael Artz 2006-07-27 00:13:03 Re: Storing an ordered list