Thread: bigint in mysql
View Single Post
  #3  
Old June 29th 03, 05:57 PM
Po Boy
external usenet poster
 
Posts: n/a
Default bigint in mysql

On Sat, 28 Jun 2003 11:24:00 +0000, Allan Adler wrote:

The documentation for mysql leaves me a little puzzled as to how to
declare the object ID. I'm not even sure whether it really supports 64
bit unsigned integers or only 63 bits. There are some comments about
giving wrong answers at the most significant bits. It also says something
about declaring the bigint as a string and mysql being smart enough to
automatically convert it to an integer. It also says something about
arithmetic with these bigints being treated using doubles, i.e. floating
point, which it is the purpose of the string version to avoid.


Yeah. I'd use an unsigned bigint for this column. Don't do any arithmetic
except for bit shifting kids of things. That's the kind of math you'd be
doing anyway in order to get at certain bits in that ID.


Question 1: How do I declare the object ID (e.g. calling it objID) as a 64
bit integer in mysql?


Something like

create table FooTable (
ObjID unsigned bigint not null default 0
);

ought to define that column in a table. IS that what you're looking for?
You'll probably want to put more stuff into that table, I imagine.


Question 2: How should I extract the various items skyVersion, field, run,
rerun, camcol, obj from objID? I could do it, for example, by first dividing
objID by 2^16 to get obj as a remainder, dividing the quotient by something
else to get the next field as the remainder, dividing the new quotient
and so on. Would that get me involved in the floating point stuff that
one is trying to avoid? In any case, is there a mysql command that will
simply partition a 64 bit binary int into specified pieces?


use bitwise functions, like "&" for AND to and things against bitmask
numbers and "" and "" to shift things around.

http://www.mysql.com/doc/en/Bit_functions.html

Using these functions, you can more quickly and accurately pull certain
ranges of bits out of the ID.

This kind of work is similar to how people treat IP addresses and netmasks
and such. You may find examples of working with those numbers easier to
come across on the net.

Hope it helps.

-pb