mysqldude
Error codes › 1690

MySQL & MariaDB error 1690: BIGINT UNSIGNED value is out of range

Error message… value is out of range in '…'
Example from our test runs: BIGINT UNSIGNED value is out of range in '(`t_0`.`stock`.`qty` - 5)' (5.6.51)

An arithmetic expression produced a value outside the range of its type, most often subtracting from an UNSIGNED column, where the result would be negative.

MySQLMariaDB
SymbolER_DATA_OUT_OF_RANGEER_DATA_OUT_OF_RANGE
SQLSTATE2200322003
TypeServer errorServer error
Versionssince 5.5.63 activeevery release since 5.5 active

What it means

BIGINT UNSIGNED value is out of range in '(stock.qty - 5)'. When one operand is UNSIGNED, MySQL computes the result as UNSIGNED too, so 2 - 5 can’t be represented. The same error appears for signed overflow (BIGINT value is out of range), for example 9223372036854775807 + 1.

Why it happens

  • Subtracting on UNSIGNED columns: stock, balances, counters, UNIX_TIMESTAMP() differences.
  • Multiplying large values in a report.
  • It has been an error since MySQL 5.5.5; before that, the result silently wrapped around to a huge number.

How to fix it

  • Cast before the arithmetic: CAST(qty AS SIGNED) - 5.
  • Or enable NO_UNSIGNED_SUBTRACTION in sql_mode so subtraction results are signed.
  • Reconsider UNSIGNED for values that can legitimately go negative in calculations.

Reproduce it yourself

These steps are the exact test our harness runs. Use a scratch server, never production.

  1. Connect with mysql -u root -p and create a scratch database and the test data:

    CREATE DATABASE demo;
    USE demo;
    CREATE TABLE stock (item VARCHAR(10), qty INT UNSIGNED);
    INSERT INTO stock VALUES ('a', 2);
  2. Run:

    SELECT qty - 5 FROM stock;

You get: BIGINT UNSIGNED value is out of range in '`t_0`.`stock`.`qty` - 5'(11.8.9)

Verified fixes

  1. Cast to SIGNED before subtracting (or enable NO_UNSIGNED_SUBTRACTION)

    SELECT CAST(qty AS SIGNED) - 5 FROM stock;

Tested on

StepMySQLMariaDB
5.65.78.08.4910.610.1111.411.8
Subtraction on an UNSIGNED column goes below zero
repro
✓ 1690✓ 1690✓ 1690✓ 1690✓ 1690✓ 1690✓ 1690✓ 1690✓ 1690
Cast to SIGNED before subtracting (or enable NO_UNSIGNED_SUBTRACTION)
fix
✓✓✓✓✓✓✓✓✓
Subtraction on an UNSIGNED column goes below zero repro
MySQL 5.6✓ 16905.7✓ 16908.0✓ 16908.4✓ 16909✓ 1690
MariaDB 10.6✓ 169010.11✓ 169011.4✓ 169011.8✓ 1690
Cast to SIGNED before subtracting (or enable NO_UNSIGNED_SUBTRACTION) fix
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
✓works ✓ 1062fails with the error the step demonstrates ⚠works with a warning ≠runs, result differs ✗fails Tested 2026-11-25 on 5.6.51, 5.7.44, 8.0.46, 8.4.13, 9.7.4, 10.6.28, 10.11.19, 11.4.13, 11.8.9

Related errors

  • 1264 ER_WARN_DATA_OUT_OF_RANGEexplained
  • 1406 ER_DATA_TOO_LONGexplained