Bug #2595 | bigint update from string failure | ||
---|---|---|---|
Submitted: | 31 Jan 2004 8:48 | Modified: | 6 Feb 2004 2:52 |
Reporter: | [ name withheld ] | Email Updates: | |
Status: | Won't fix | Impact on me: | |
Category: | MySQL Server | Severity: | S3 (Non-critical) |
Version: | 4.0.17-standard | OS: | Linux (Linux on Intel) |
Assigned to: | Sergei Golubchik | CPU Architecture: | Any |
[31 Jan 2004 8:48]
[ name withheld ]
[4 Feb 2004 1:29]
Sergei Golubchik
two issues here. first: when you convert a string to a number you always get a floating point number in MySQL. It is documented. As bigint has a higher precision than float, last bits are lost: mysql> select "922337203685477580"+1; +------------------------+ | "922337203685477580"+1 | +------------------------+ | 9.2233720368548e+17 | +------------------------+ 1 row in set (0.00 sec) mysql> select "922337203685477580"+0; +------------------------+ | "922337203685477580"+0 | +------------------------+ | 9.2233720368548e+17 | +------------------------+ 1 row in set (0.00 sec) second problem is with representing hex numbers as a string. You can do it, but do not expect them to be converted to numbers automatically. It happened out that in Linux or SGI atof("0x80") works, but not in FreeBSD or Solaris or AIX. So, we are replacing it with our atof() implementation which is faster and works identically on all systems. It does NOT support hexadecimal numbers (it was never the intention, and it need not to according to SQL:2003 standard).
[4 Feb 2004 13:50]
[ name withheld ]
Would it be possible to add a MySQL function to perform conversion from hexadecimal to integer values?
[6 Feb 2004 2:52]
Sergei Golubchik
You can do it with CONV() function: CONV("3AB03", 16, 10) you need to remove "0x" prefix - CONV(MID("0x0BEC", 3), 16, 10)