Error
Error Code:
1690
MySQL Error 1690: Value Out Of Range
Description
MySQL Error 1690 occurs when you attempt to insert or update data into a column with a value that exceeds the permissible range defined by its data type or explicit constraints. This indicates a violation of the maximum or minimum limits for numeric, date, or other data types.
Error Message
%s value is out of range in '%s'
Known Causes
4 known causesData Type Overflow
Attempting to store a value (e.g., a large number) into a column whose data type (e.g., TINYINT, SMALLINT) has a smaller maximum or minimum limit than the provided value.
Signed/Unsigned Mismatch
Trying to insert a negative value into an UNSIGNED integer column, or a value exceeding the signed limit into a SIGNED column when an UNSIGNED column was intended.
Invalid Date/Time Value
Providing a date or time value that falls outside the valid range for a DATE, DATETIME, or TIMESTAMP column (e.g., '2023-02-30' for a date).
Implicit Type Conversion Issues
MySQL's automatic attempt to convert a value from one data type to another results in an 'out of range' condition for the target column.
Solutions
3 solutions available1. Identify and Correct the Offending Data Type and Value medium
Determine the data type and value causing the out-of-range error and adjust either the data or the data type.
1
Examine the error message carefully. The `%s` placeholders will typically indicate the specific value and the column or expression that caused the issue. For example, '12345678901234567890' value is out of range in 'your_column_name'.
2
Identify the column or expression mentioned in the error message. Check its defined data type in your MySQL schema. You can do this using `DESCRIBE table_name;` or by querying `INFORMATION_SCHEMA.COLUMNS`.
DESCRIBE your_table_name;
3
Compare the value causing the error with the maximum and minimum values allowed for that data type. For example, a BIGINT can store values up to 2^63 - 1 (signed) or 2^64 - 1 (unsigned).
4
If the data value is indeed too large or too small, you have two primary options:
1. **Correct the data:** If the value is a mistake, update the record with a valid value.
2. **Modify the data type:** If the data is legitimate but exceeds the current data type's range, alter the column to a more appropriate data type (e.g., from INT to BIGINT, or from DECIMAL(10,2) to DECIMAL(20,5)).
1. **Correct the data:** If the value is a mistake, update the record with a valid value.
2. **Modify the data type:** If the data is legitimate but exceeds the current data type's range, alter the column to a more appropriate data type (e.g., from INT to BIGINT, or from DECIMAL(10,2) to DECIMAL(20,5)).
5
To correct the data (Option 1):
sql
UPDATE your_table_name SET your_column_name = 'valid_value' WHERE some_condition;
sql
UPDATE your_table_name SET your_column_name = 'valid_value' WHERE some_condition;
UPDATE your_table_name SET your_column_name = 'valid_value' WHERE some_condition;
6
To modify the data type (Option 2):
**Example: Changing INT to BIGINT**
sql
ALTER TABLE your_table_name MODIFY COLUMN your_column_name BIGINT;
**Example: Changing DECIMAL precision**
sql
ALTER TABLE your_table_name MODIFY COLUMN your_column_name DECIMAL(20, 5);
*Note: Always back up your data before performing ALTER TABLE operations, especially when changing data types, as it can lead to data loss if not handled carefully.*
**Example: Changing INT to BIGINT**
sql
ALTER TABLE your_table_name MODIFY COLUMN your_column_name BIGINT;
**Example: Changing DECIMAL precision**
sql
ALTER TABLE your_table_name MODIFY COLUMN your_column_name DECIMAL(20, 5);
*Note: Always back up your data before performing ALTER TABLE operations, especially when changing data types, as it can lead to data loss if not handled carefully.*
ALTER TABLE your_table_name MODIFY COLUMN your_column_name BIGINT;
ALTER TABLE your_table_name MODIFY COLUMN your_column_name DECIMAL(20, 5);
2. Review Application Logic for Incorrect Calculations or Data Insertion advanced
Investigate the application code that is generating or inserting the data to find logical errors.
1
Trace the execution path of your application code that interacts with the MySQL database, specifically focusing on the point where the problematic data is generated or inserted.
2
Look for any calculations that might produce values exceeding the defined data type limits. This could involve arithmetic operations, string concatenations that result in numbers, or conversions between data types.
3
If you are using prepared statements or ORMs, ensure that the data types being bound to the statement or passed to the ORM methods are consistent with the database schema. An unexpected type conversion on the application side could lead to this error.
4
Add logging or debugging statements within your application code to inspect the values just before they are sent to the database. This will help pinpoint the exact value and the stage at which it becomes out of range.
5
Implement validation checks within your application logic *before* attempting to insert or update data. This allows you to catch and handle out-of-range values gracefully, perhaps by returning an error to the user or logging the issue.
3. Handle Numeric Overflow in Expressions or Subqueries medium
Address situations where intermediate results in complex queries exceed data type limits.
1
If the error occurs within a complex query involving calculations, subqueries, or function calls, analyze the expression or subquery that is generating the out-of-range value. The error message should point to the specific expression.
2
Identify the data types involved in the calculation. If an intermediate calculation results in a value larger than the target data type can hold, it will cause this error. For example, multiplying two large INT values might exceed the INT range.
3
Cast the operands to a larger data type *before* performing the operation. For example, if you are multiplying two INT columns, cast them to BIGINT first.
SELECT CAST(int_column1 AS SIGNED BIGINT) * CAST(int_column2 AS SIGNED BIGINT) FROM your_table;
4
If the error originates from a subquery, ensure that the subquery's result set's values are within the expected range for the context in which they are used.
5
Consider using `DECIMAL` for precise calculations with potentially large numbers, especially when dealing with financial data, to avoid floating-point inaccuracies and range issues.