#MySQL CAST can handle overflows that occur during the evaluation of numeric expressions. Suppose that if a numeric expression evaluation produces an overflow, MySQL will reflect an error message. Now to handle this overflow we can change the value to UNSIGNED with the help of CAST.
For example, when adding 1 to the maximum value of BIGINT, MySQL generates an error due to overflow as shown below -
mysql> Select 9223372036854775807 + 1; ERROR 1690 (22003): BIGINT value is out of range in '(9223372036854775807+1)'
Now, with the help of CAST, MySQL handles this as follows Overflow:
mysql> Select CAST(9223372036854775807 AS UNSIGNED) +1; +------------------------------------------+ | CAST(9223372036854775807 AS UNSIGNED) +1 | +------------------------------------------+ | 9223372036854775808 | +------------------------------------------+ 1 row in set (0.07 sec)
The above is the detailed content of How does MySQL CAST handle overflow?. For more information, please follow other related articles on the PHP Chinese website!