
MySql 5.0 Unsigned Integer Underflow
August 1, 2008This is tested on MySql 5.0.60-r1 (gentoo portage).
mysql> system uname -a Linux meepo 2.6.24-hardened-r3 #11 Mon Jul 28 07:31:20 MYT 2008 i686 AMD Sempron(tm) 2200+ AuthenticAMD GNU/Linux mysql> SELECT VERSION(); +------------+ | VERSION() | +------------+ | 5.0.60-log | +------------+ 1 row in set (0.00 sec) mysql> system uname -a Linux gentoo 2.6.24-hardened-r3 #11 Mon Jul 28 07:31:20 MYT 2008 i686 AMD Sempron(tm) 2200+ AuthenticAMD GNU/Linux mysql> SELECT CAST( -1 AS UNSIGNED ); +------------------------+ | CAST( -1 AS UNSIGNED ) | +------------------------+ | 18446744073709551615 | +------------------------+ 1 row in set (0.00 sec) mysql> SELECT CAST( 0 AS UNSIGNED ) - 1; +---------------------------+ | CAST( 0 AS UNSIGNED ) - 1 | +---------------------------+ | 18446744073709551615 | +---------------------------+ 1 row in set (0.00 sec) mysql>
It is expected that any negative unsigned value to be “casted” to 0.
I have filed a bug report at bugs.mysql.com
http://bugs.mysql.com/bug.php?id=38512
Edit:
Its now fixed and closed. They introduced a strict mode instead of rounding the value to 0. You should upgrade your MySql now.