Bug #63834 | Add isNumeric function | ||
---|---|---|---|
Submitted: | 22 Dec 2011 4:47 | Modified: | 23 Dec 2011 19:58 |
Reporter: | Eric Kent | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: Errors | Severity: | S4 (Feature request) |
Version: | 5.5.19 | OS: | Windows (Windows 7) |
Assigned to: | CPU Architecture: | Any |
[22 Dec 2011 4:47]
Eric Kent
[22 Dec 2011 18:18]
Sveta Smirnova
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://dev.mysql.com/doc/ and the instructions on how to report a bug at http://bugs.mysql.com/how-to-report.php Singe SELECT query returns this warning too: mysql> \W Show warnings enabled. mysql> set @sValue='3234a'; Query OK, 0 rows affected (0.00 sec) mysql> select if (@sValue = cast(cast(@sValue as unsigned) as char), true, false ) ; +----------------------------------------------------------------------+ | if (@sValue = cast(cast(@sValue as unsigned) as char), true, false ) | +----------------------------------------------------------------------+ | 0 | +----------------------------------------------------------------------+ 1 row in set, 1 warning (0.00 sec) Warning (Code 1292): Truncated incorrect INTEGER value: '3234a'
[23 Dec 2011 15:19]
Eric Kent
I re-read the Cast Functions page and noticed the user comment at the bottom from Anne Blankert. That is the only part of the documentation that I found that addresses this. Please let me know if it is discussed anywhere else. Based on that note, I tried: select if ('3234a' = cast( 0 + '3234a' as char), true, false ) ; and I got another warning: Warning 1292 Truncated incorrect DOUBLE value: '3234a' This is a bug. Other databases handle this properly. I found a better work around by using: return sValue not regexp '[^0-9]'; This will work for unsigned, which is what I needed. It could be extended for floating points by adding extra clauses to the regular expression. Other databases have a native isnumeric function. I recommend adding this to MySQL.
[23 Dec 2011 16:12]
Eric Kent
I checked the ISO SQL standard, and it does say that if the string value is not strictly a numeric, "then an exception condition is raised" Therefore, this is not a bug. I changed the severity to a feature request. Other databases do handle this the way I expected. This would be an extension to the ISO standard. I would also recommend that the documentation explicitly discuss this.
[23 Dec 2011 19:58]
Sveta Smirnova
Thank you for the reasonable feature request.