MySQL 8.4Lab-verified · 2026-11-29

MySQL ERROR 1690 (22003): BIGINT UNSIGNED value is out of range

A subtraction involving an UNSIGNED column produced a negative number, which an unsigned result cannot hold.

MySQL 8.4.13
1690 (22003): BIGINT UNSIGNED value is out of range in '(`lab_a`.`stock`.`qty` - 5)'

Jump to a cause

  1. 01Subtracting a number from an UNSIGNED column in SELECT
  2. 02An UPDATE that would make stock negative
  3. 03Subtracting one UNSIGNED column from another

Lab-verifiedReproduced and fixed on MySQL 8.4.13 · 2026-11-29 · container image mysql:8.4

When an expression subtracts from an INT UNSIGNED column, MySQL computes the result as unsigned too. If the result would go below 0, MySQL 8.4 stops the statement with ERROR 1690 BIGINT UNSIGNED value is out of range, and the message shows the exact expression, such as qty - 5 with the full column name.

It appears in a plain SELECT as well, not only when saving data. Below are three cases: a calculated column in SELECT, an UPDATE that would make stock negative, and the difference of two UNSIGNED columns. The message is in English only; MySQL has no Korean or Japanese translation for it.

01Subtracting a number from an UNSIGNED column in SELECT

stock.qty is int unsigned (checked with SHOW COLUMNS FROM stock LIKE 'qty';). Item 1 has qty 3, so SELECT item_id, qty - 5 AS after_out FROM stock; would give -2, and the whole query failed with ERROR 1690.

Converting the column first, CAST(qty AS SIGNED) - 5, returned -2 for item 1 and 5 for item 2.

Setup
Setuprun as lab_a
CREATE TABLE stock (item_id INT PRIMARY KEY, qty INT UNSIGNED);
INSERT INTO stock VALUES (1, 3), (2, 10);
OUTPUT
Query OK, 0 rows affected (0.02 sec)

Query OK, 2 rows affected (0.01 sec)
Records: 2  Duplicates: 0  Warnings: 0
Reproducerun as lab_a
SELECT item_id, qty - 5 AS after_out FROM stock;
✕ ERROR
ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '(`lab_a`.`stock`.`qty` - 5)'
Checkrun as lab_a
SHOW COLUMNS FROM stock LIKE 'qty';
OUTPUT
+-------+--------------+------+-----+---------+-------+
| Field | Type         | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| qty   | int unsigned | YES  |     | NULL    |       |
+-------+--------------+------+-----+---------+-------+
1 row in set (0.00 sec)

Use this when a negative result is a valid answer, for example to show a shortage.

After the fixrun as lab_a
SELECT item_id, CAST(qty AS SIGNED) - 5 AS after_out FROM stock ORDER BY item_id;
✓ SUCCESS
+---------+-----------+
| item_id | after_out |
+---------+-----------+
|       1 |        -2 |
|       2 |         5 |
+---------+-----------+
2 rows in set (0.00 sec)

02An UPDATE that would make stock negative

Item 1 has qty 3. UPDATE stock SET qty = qty - 5 WHERE item_id = 1; failed with ERROR 1690, and the row stayed at 3.

Adding a condition AND qty >= 5 to the UPDATE made it safe. For item 1 it matched 0 rows and changed nothing; for item 2 (qty 10) it changed 1 row to 5. No error either way.

Setup
Setuprun as lab_a
CREATE TABLE stock (item_id INT PRIMARY KEY, qty INT UNSIGNED);
INSERT INTO stock VALUES (1, 3), (2, 10);
OUTPUT
Query OK, 0 rows affected (0.01 sec)

Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0
Reproducerun as lab_a
UPDATE stock SET qty = qty - 5 WHERE item_id = 1;
✕ ERROR
ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '(`lab_a`.`stock`.`qty` - 5)'
Checkrun as lab_a
SELECT item_id, qty FROM stock WHERE item_id = 1;
OUTPUT
+---------+------+
| item_id | qty  |
+---------+------+
|       1 |    3 |
+---------+------+
1 row in set (0.00 sec)

Check the affected row count in the application. 0 rows means there was not enough stock.

After the fixrun as lab_a
UPDATE stock SET qty = qty - 5 WHERE item_id = 1 AND qty >= 5;
UPDATE stock SET qty = qty - 5 WHERE item_id = 2 AND qty >= 5;
SELECT item_id, qty FROM stock ORDER BY item_id;
✓ SUCCESS
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0  Changed: 0  Warnings: 0

Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

+---------+------+
| item_id | qty  |
+---------+------+
|       1 |    3 |
|       2 |    5 |
+---------+------+
2 rows in set (0.00 sec)

03Subtracting one UNSIGNED column from another

target and actual are both INT UNSIGNED. In October actual (120) was above target (100), so target - actual would be -20 and the query failed with ERROR 1690. The message shows both columns.

SELECT @@sql_mode; showed the default mode without NO_UNSIGNED_SUBTRACTION. After SET SESSION sql_mode = CONCAT(@@sql_mode, ',NO_UNSIGNED_SUBTRACTION'); the same query returned -20 for 2026-10 and 20 for 2026-11.

Setup
Setuprun as lab_a
CREATE TABLE sales_plan (month CHAR(7) PRIMARY KEY, target INT UNSIGNED, actual INT UNSIGNED);
INSERT INTO sales_plan VALUES ('2026-10', 100, 120), ('2026-11', 100, 80);
OUTPUT
Query OK, 0 rows affected (0.02 sec)

Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0
Reproducerun as lab_a
SELECT month, target - actual AS shortfall FROM sales_plan;
✕ ERROR
ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '(`lab_a`.`sales_plan`.`target` - `lab_a`.`sales_plan`.`actual`)'
Checkrun as lab_a
SELECT @@sql_mode;
OUTPUT
+-----------------------------------------------------------------------------------------------------------------------+
| @@sql_mode                                                                                                            |
+-----------------------------------------------------------------------------------------------------------------------+
| ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION |
+-----------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

This only changed the current session. CAST(... AS SIGNED) on one column, as in the first case, fixes a single query without touching sql_mode.

After the fixrun as lab_a
SET SESSION sql_mode = CONCAT(@@sql_mode, ',NO_UNSIGNED_SUBTRACTION');
SELECT month, target - actual AS shortfall FROM sales_plan ORDER BY month;
✓ SUCCESS
Query OK, 0 rows affected (0.00 sec)

+---------+-----------+
| month   | shortfall |
+---------+-----------+
| 2026-10 |       -20 |
| 2026-11 |        20 |
+---------+-----------+
2 rows in set (0.00 sec)

FAQ

Why do I get BIGINT UNSIGNED value is out of range in a SELECT?

Because the SELECT subtracts from an UNSIGNED column and one row gives a negative result. On this page qty - 5 with qty 3 failed the whole query, even though no data was being saved.

My column is INT UNSIGNED. Why does the message say BIGINT UNSIGNED?

MySQL evaluates the arithmetic as BIGINT UNSIGNED, so the message names that type, not the column type. SHOW COLUMNS showed the column as int unsigned.

How do I allow a negative result?

Cast the column: CAST(qty AS SIGNED) - 5 returned -2. Or add NO_UNSIGNED_SUBTRACTION to sql_mode; on this page that made target - actual return -20.

How do I stop stock from going below zero in an UPDATE?

Add the condition to the WHERE clause, like WHERE item_id = 1 AND qty >= 5. When stock was 3 it updated 0 rows instead of failing.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary users created for the test, each with full rights on a database of the same name (its default database); root is the administrator. MySQL 8.4.13