Back to top

127 is the magic number (so is 128 and 32 and...)

So, today I'm working on a fun module I plan to use as the basis for my presentation at BarCamp and I, um, keep running into unexpected situations. Most of the time these involve the number 127 in the database. I bang my head on the problem for a couple seconds and then add in enough debugging statements to see that the database is either stopping duplicate keys or rounding a number down to 127 or...

I created the table with tinyints in several cases and the largest number available in a tinyint is 127. So when I insert 523 into the database, the database happily (and silently to me) inserts the record as 127. I've now hit similar problems twice and both times said "man, 127, that's a weird number to be stuck on..."

Note to self: 127 isn't just a random weird number to be stuck on - it's a common limit in programming. Remember that.

People Involved: 


for the record

For the record, so is 65535

user warning: Duplicate entry '65535' for key 1 query

Means I need a bigger column than a tiny int...