Social Icons

Pages

Показват се публикациите с етикет MYSQL issues. Показване на всички публикации
Показват се публикациите с етикет MYSQL issues. Показване на всички публикации

How to fix "MySQL error BIGINT UNSIGNED value is out of range" ?

You are doing simple subtract of two columns in MySQL

SELECT (A-B) from table;

but you get ERROR 1690 (22003): BIGINT UNSIGNED value is out of range. What you do?
Do not panic.
From the MySQL data types docs:
BIGINT[(M)] [UNSIGNED] [ZEROFILL]
A large integer. The signed range is -9223372036854775808 to 9223372036854775807. The unsigned range is 0 to 18446744073709551615.

So you are obviously subtracting columns of type UNSIGNED and result is negative. To solve this you need to cast them to SIGNED , even if you do not heed to store the result - just displaying.

SELECT (CAST(A AS SIGNED)-CAST(B AS SIGNED)) from table;