I need to store 128 bits unsigned integers into MySQL and I was wondering what is the best data type to store such big numbers.
Right now, I'm using binary(16)
but that involves a lot of conversion function pack(/huge number in hex .../)
.
Is there a best datatype to store a 128 bit unsigned integer?
Best Answer
I don't know what the best way necessarily is to store it -- but there's at least a better option than using a
varchar(39)
(orvarchar(40)
if you needed it signed) ; instead use adecimal(39,0)
. From the mysql docs:It's stored packed, so it'll take up less space than the varchar (18 bytes, if I'm doing my math right), and I'd hope you'd be able to do math on it directly, but I've never tried with that large of a number to see what happens.