If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > store userdefined rank order

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-02-07, 03:45
tas tas is offline
Registered User
 
Join Date: Oct 2007
Posts: 3
Question store userdefined rank order

I have something like a link list, where a user itself can define, in which order those links are displayed ( depended on their needs, preferences )... so they
can for example drag the last link and drop it somewhere between the rest of the links..

this rank order has to be stored somehow in my DB, hence the same order can be displayed when the user stops by the next time..

First I thought about a INT field 'rank', where the actual rank number (i.e. 1, 2, 3 etc.) is stored.. but that turned out to be crappy.. because almost everytime the user drag & drops a link, I have to change a lot of records to keep the data integrity..

Then I had another idea.. change that INT field 'rank' to a FLOAT field. when a user now drags a link and drops it between two other links, I only fetch the rank number of those two links, take the average (sum up, divide 2) and this is my new page rank..

but I'm not overhappy with this solution... I think, there must be something else..


anyone can help??


thanks in advance
Reply With Quote
  #2 (permalink)  
Old 10-02-07, 07:25
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
that is actually a very good solution
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 10-02-07, 08:10
tas tas is offline
Registered User
 
Join Date: Oct 2007
Posts: 3
Quote:
Originally Posted by r937
that is actually a very good solution
it was the best I could come up with..

but isn't there a sort of pattern to solve this issue? I'm sure, I'm not the first one doing this (:
Reply With Quote
  #4 (permalink)  
Old 10-02-07, 08:19
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
yes, i have seen people try to solve this in many different ways

all of which involve re-sequencing existing rows after an insert

if using consecutive sequence numbers, this involves updating maybe half the rows in the entire table!!

at one point i used to recommend people assign their sequence numbers in increments of 100, so that you can, for example, easily fit 350 in between 300 and 400

but this can also lead to the need to re-sequence

floating point numbers have the advantage that you should never need to re-sequence, as there will always be a valid number in between any two given numbers
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 10-02-07, 09:00
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Quote:
Originally Posted by r937
floating point numbers have the advantage that you should never need to re-sequence, as there will always be a valid number in between any two given numbers
... in theory! In practice computers are finite, and there must come a point where you cannot go further. But this still sounds like the best solution!
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #6 (permalink)  
Old 10-02-07, 09:16
tas tas is offline
Registered User
 
Join Date: Oct 2007
Posts: 3
Quote:
Originally Posted by r937
yes, i have seen people try to solve this in many different ways

all of which involve re-sequencing existing rows after an insert

if using consecutive sequence numbers, this involves updating maybe half the rows in the entire table!!

at one point i used to recommend people assign their sequence numbers in increments of 100, so that you can, for example, easily fit 350 in between 300 and 400

but this can also lead to the need to re-sequence

floating point numbers have the advantage that you should never need to re-sequence, as there will always be a valid number in between any two given numbers
ah yeah.. now I'm really proud of myself.. (:

@andrewst: that's true, but I think for my app it will suffice.. do you know how many decimal places a float can have?
Reply With Quote
  #7 (permalink)  
Old 10-02-07, 10:49
loquin loquin is offline
Super Moderator
 
Join Date: Jun 2004
Location: Arizona, USA
Posts: 1,797
Quote:
Originally Posted by tas
ah yeah.. now I'm really proud of myself.. (:

@andrewst: that's true, but I think for my app it will suffice.. do you know how many decimal places a float can have?
That really depends on the database implementation...

Many databases use implementations of IEEE Standard 754 for Binary Floating-Point numbers. IEEE floating points are single precision (up to 6 digits of precision) or double precision (15 digits precision).

However, database vendors will often include aribritary precision NUMERIC types as well, which support floating numbers of aribritaty precision (up to some limit...)

For example, both Oracle and SQL Server support NUMERIC data types with up to 38 digits of precision, whereas PostgreSQL supports NUMERIC data types with up to 1000 digits of precision by default. (If you want to recompile PostgreSQL, you can define the upper limit to any length you desire...) However, arithmetic on numeric values is slow when compared to the integer types, or to the IEEE floating-point types. (In SQL Server, Float and Real correspond to IEEE Double and Single Precision, respectively.)
__________________
Lou
使大吃一惊
"Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
"I have my standards. They may be low, but I have them!" - Bette Middler
"It's a book about a Spanish guy named Manual. You should read it." - Dilbert


Last edited by loquin; 10-02-07 at 11:25.
Reply With Quote
  #8 (permalink)  
Old 10-04-07, 14:14
TravisJ TravisJ is offline
Registered User
 
Join Date: Aug 2007
Posts: 10
I kind of like the idea of the floats, but storing integers and changing the surrounding rank values isn't too slow if you have a small number of items to change. You might just want to try this first, and profile it to see how slow it actually is.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On