MySQL & MariaDB error 1264: Out of range value for column
Out of range value for column 'age' at row 1 (5.6.51) A number doesn't fit the column's type (TINYINT holds -128 to 127, INT about +/-2.1 billion, UNSIGNED no negatives). An error in strict mode, a silent clip to the limit otherwise.
| MySQL | MariaDB | |
|---|---|---|
| Symbol | ER_WARN_DATA_OUT_OF_RANGE | ER_WARN_DATA_OUT_OF_RANGE |
| SQLSTATE | 22003 | 22003 |
| Type | Server error | Server error |
| Versions | every release since 5.0 active | every release since 5.5 active |
What it means
The value is outside the range of the column’s numeric type. With strict mode (STRICT_TRANS_TABLES, the default since MySQL 5.7 and MariaDB 10.2.4) the statement fails. Without it, the server stores the nearest limit (300 becomes 127 in a TINYINT) and only raises warning 1264.
Why it happens
- The column is too small:
TINYINTfor an age is fine, for a quantity it isn’t;INTfor IDs, byte counts or phone numbers eventually overflows. - A negative value into an
UNSIGNEDcolumn. DECIMAL(5,2)holds at most 999.99, so 1000 is out of range.- An
AUTO_INCREMENTcolumn reaching the top of its type. That surfaces as 1062 or 167 instead, see 1062.
How to fix it
- Widen the column:
ALTER TABLE t MODIFY qty INT;(orBIGINT). On a big table this rebuilds it, so plan the change. - Validate input in the application if the limit is a business rule.
- Don’t turn off strict mode to hide this: the value then silently changes to the limit, which is worse than an error.
Reproduce it yourself
These steps are the exact test our harness runs. Use a scratch server, never production.
Connect with
mysql -u root -pand create a scratch database and the test data:CREATE DATABASE demo; USE demo; CREATE TABLE t (age TINYINT);Run:
SET SESSION sql_mode = 'STRICT_TRANS_TABLES'; INSERT INTO t VALUES (300);
You get: Out of range value for column 'age' at row 1(11.8.9)
Verified fixes
Widen the column to a type that holds the value
SET SESSION sql_mode = 'STRICT_TRANS_TABLES'; ALTER TABLE t MODIFY age SMALLINT; INSERT INTO t VALUES (300); SELECT age FROM t;
Tested on
| Step | MySQL | MariaDB | |||||||
|---|---|---|---|---|---|---|---|---|---|
| 5.6 | 5.7 | 8.0 | 8.4 | 9 | 10.6 | 10.11 | 11.4 | 11.8 | |
| Insert 300 into a TINYINT (range -128 to 127) in strict mode repro | ✓ 1264 | ✓ 1264 | ✓ 1264 | ✓ 1264 | ✓ 1264 | ✓ 1264 | ✓ 1264 | ✓ 1264 | ✓ 1264 |
| Without strict mode the value is silently clipped to 127 (warning 1264) version check | ⚠ 1264 | ⚠ 3090,1264 | ⚠ 1264 | ⚠ 1264 | ⚠ 1264 | ⚠ 1264 | ⚠ 1264 | ⚠ 1264 | ⚠ 1264 |
| Widen the column to a type that holds the value fix | ✓ | ⚠ 3135,3090 | ⚠ 3135 | ⚠ 3135 | ⚠ 3135 | ✓ | ✓ | ✓ | ✓ |
What the warnings and failures say (4)
- Without strict mode the value is silently clipped to 127 (warning 1264) (MySQL 5.6, MySQL 8.0, MySQL 8.4, MySQL 9, MariaDB 10.6, MariaDB 10.11, MariaDB 11.4, MariaDB 11.8): warning 1264: Out of range value for column 'age' at row 1
- Without strict mode the value is silently clipped to 127 (warning 1264) (MySQL 5.7): warning 3090: Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release.; warning 1264: Out of range value for column 'age' at row 1
- Widen the column to a type that holds the value (MySQL 5.7): warning 3135: 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with stric; warning 3090: Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release.
- Widen the column to a type that holds the value (MySQL 8.0, MySQL 8.4, MySQL 9): warning 3135: 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with stric
Related errors
How the message changed between versions
| MySQL from | Symbol | Message |
|---|---|---|
| 5.0.96 | ER_WARN_DATA_OUT_OF_RANGE | Out of range value adjusted for column '%s' at row %ld |
| 5.1.77 | ER_WARN_DATA_OUT_OF_RANGE | Out of range value for column '%s' at row %ld |