How to Solve / Workaround the SQL 1690 Error

In this post is a guided demonstration of how to fix the MySQL ERROR 1690. We start with defining some variables in MySQL. Then we create new variables by casting the variables we just created as unsigned. Then we do a deletion which would result in a negative number (impossible with unsigned variables). Then we cast the numbers as signed so can can do our arithmetic.


mysql> SET @a = 100;

mysql> SET @b = 200;

mysql> SET @a2 = CAST(@a as unsigned);

mysql> SET @b2 = CAST(@b as unsigned);


mysql> SELECT @a2 - @b2;

ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '((@`a2`) - (@`b2`))


mysql> SELECT CAST(@a2 as signed) - CAST(@b2 as signed);

+-------------------------------------------+

| CAST(@a2 as signed) - CAST(@b2 as signed) |

+-------------------------------------------+

|                                      -100 |

+-------------------------------------------+


Image: Demonstrating SQL Error 1690


Comments