I use MySQL in strict mode ( SET sql_mode = 'STRICT_TRANS_TABLES' ) to convert all warnings to errors. However, I have a query that is expected to generate warnings because it is trying to convert a VARCHAR field that may be empty or contain integer letters.
Example:
mysql> select CAST("123b" AS SIGNED); +------------------------+ | CAST("123b" AS SIGNED) | +------------------------+ | 123 | +------------------------+ 1 row in set, 1 warning (0.00 sec) mysql> show warnings; +---------+------+-------------------------------------------+ | Level | Code | Message | +---------+------+-------------------------------------------+ | Warning | 1292 | Truncated incorrect INTEGER value: '123b' | +---------+------+-------------------------------------------+ 1 row in set (0.00 sec)
Is there a way to suppress a warning caused by CAST() without disabling strict mode? Or, conversely, can you disable strict mode for one request or function (something like the @ operator in PHP) without calling SET twice to temporarily disable strict mode?
Background: I have a table with street numbers. Most of them are numeric, but some of them contain letters at the end. To implement a simplified โnatural sortโ, I would like to use ORDER BY CAST (StreetNr AS SIGNED), StreetNr , and the value returned by CAST () would be great for first-level sorting.
Udo g source share