Main
Latest
- My girlfriend?
- Parsing an hCard using getElementsByClassName in F...
- Jaiku on Google App Engine
- Twitter on Google App Engine
- wget has rounding mistake or something?
- Twitter Replies
- Blog Reopened
- Blog closed (temporarily)
- "I won't forget" by Jacques FT. Pebbles
- Jaiku Revisited
Archives
- June 2004
- July 2004
- August 2004
- September 2004
- October 2004
- November 2004
- December 2004
- January 2005
- February 2005
- March 2005
- April 2005
- May 2005
- June 2005
- July 2005
- August 2005
- September 2005
- October 2005
- November 2005
- December 2005
- January 2006
- February 2006
- March 2006
- April 2006
- May 2006
- June 2006
- July 2006
- August 2006
- September 2006
- November 2006
- December 2006
- January 2007
- February 2007
- March 2007
- April 2007
- May 2007
- June 2007
- July 2007
- August 2007
- September 2007
- October 2007
- November 2007
- December 2007
- January 2008
- February 2008
- March 2008
- April 2008
- May 2008
- June 2008
- July 2008
- August 2008
- September 2008
- October 2008
- November 2008
- December 2008
- January 2009
MySQL BIGINT Calculation Weirdness
Check these out:
mysql> select 5 + 5;
+-------+
| 5 + 5 |
+-------+
| 10 |
+-------+
1 row in set (0.00 sec)
mysql> select '5' + '5';
+-----------+
| '5' + '5' |
+-----------+
| 10 |
+-----------+
1 row in set (0.00 sec)
mysql> select 4000000000000000000 + 1;
+-------------------------+
| 4000000000000000000 + 1 |
+-------------------------+
| 4000000000000000001 |
+-------------------------+
1 row in set (0.00 sec)
mysql> select '4000000000000000000' + 1;
+---------------------------+
| '4000000000000000000' + 1 |
+---------------------------+
| 4e+18 |
+---------------------------+
1 row in set (0.00 sec)
mysql> select '4000000000000000000';
+---------------------+
| 4000000000000000000 |
+---------------------+
| 4000000000000000000 |
+---------------------+
1 row in set (0.00 sec)
So basically if you surround the number with quotes, it would first take it as a string, but if it needs to convert it, it would not convert it optimally to a BIGINT and thereby you lose accuracy.
This sounds like a petty issue but it really screwed me around the other day.
Copyright © 2004-2009 Charl van Niekerk. All articles are released under the Creative Commons Attribution 2.5 South Africa licence, unless where otherwise stated.


1 Comments
Comment by
thakadu on Sunday, July 27, 2008 3:30:00 PM
Hi Charl
You may be aware already but MySQL autoconversion gets way weirder. Say you have a table that has a numeric primary key called id, enetering:
select * from my_table where id='100';
will return the same as:
select * from my_table where id=100;
That may be acceptable but whats worse is this
also returns the same thing:
select * from my_table where id='100anyjunk';
!
Post a Comment