ERROR 1367 occurs when MySQL tries to parse a value that is out of range or invalid for its data type, commonly with DOUBLE/FLOAT overflow or incorrect spatial data. Fix it by validating data types, checking numeric ranges, and using explicit CAST() functions when needed.
MySQL error 1367 is raised when the database engine encounters a value that cannot be parsed or is illegal for the specified data type during query execution. The error symbol is ER_ILLEGAL_VALUE_FOR_TYPE with SQLSTATE 22007. This typically happens when you attempt to insert or convert a value that exceeds the valid range for that data type, such as extremely large numbers for DOUBLE columns, or when spatial/geometric functions receive non-geometric values.
First, examine your table structure to see what data type the problematic column uses:
DESC your_table_name;
-- or
SHOW CREATE TABLE your_table_name;Look for the column that is causing the error and note its data type (DOUBLE, FLOAT, DECIMAL, etc.).
For DOUBLE columns, ensure values fall within the valid range:
-- Valid DOUBLE range:
-- -1.7976931348623157E+308 to -2.2250738585072014E-308
-- 0
-- 2.2250738585072014E-308 to 1.7976931348623157E+308
-- Instead of:
INSERT INTO my_table (double_col) VALUES (999999999999999999E309);
-- Use a value within range:
INSERT INTO my_table (double_col) VALUES (1.5E+10);If you need to store very large numbers, consider using DECIMAL with appropriate precision and scale instead.
When converting between data types, use explicit CAST() functions instead of relying on implicit conversion:
-- Instead of implicit conversion:
SELECT numeric_string + 5;
-- Use explicit CAST:
SELECT CAST(numeric_string AS SIGNED) + 5;
-- Common CAST targets:
CAST(value AS BINARY)
CAST(value AS CHAR)
CAST(value AS DATE)
CAST(value AS DATETIME)
CAST(value AS DECIMAL(10,2))
CAST(value AS SIGNED)
CAST(value AS UNSIGNED)This makes type conversions explicit and helps catch issues early.
If the error occurs with spatial functions like LINESTRING or POLYGON, ensure you are passing proper geometric objects:
-- Wrong (passing a variable with POINT data):
SET @point = POINT(10, 20);
SET @line = LINESTRING(@point, POINT(30, 40));
-- ERROR 1367: Illegal non geometric value found during parsing
-- Correct (building geometry directly):
SET @line = LINESTRING(POINT(10, 20), POINT(30, 40));
-- Or use ST_ functions:
SET @line = ST_LineString(POINT(10, 20), POINT(30, 40));Ensure MySQL strict mode is enabled to catch these errors early:
-- Check current SQL mode:
SELECT @@sql_mode;
-- Set strict mode (MySQL 5.7+):
SET GLOBAL sql_mode = "STRICT_TRANS_TABLES,STRICT_ALL_TABLES";
-- Or in my.cnf:
[mysqld]
sql_mode="STRICT_TRANS_TABLES,STRICT_ALL_TABLES"Strict mode rejects invalid values instead of silently truncating or converting them, helping you catch data quality issues.
After making corrections, test the problematic query:
-- Test your INSERT/UPDATE:
INSERT INTO my_table (double_col) VALUES (1.5E+10);
-- Or test your SELECT with proper casting:
SELECT * FROM my_table WHERE id > CAST("100" AS UNSIGNED);If the error still occurs, enable query logging to see the exact values being inserted:
SET GLOBAL general_log = "ON";
SET GLOBAL log_output = "TABLE";
SELECT * FROM mysql.general_log;
SET GLOBAL general_log = "OFF";Understanding MySQL type coercion is critical: MySQL 5.7.5+ uses strict SQL mode by default, which rejects invalid values. In earlier versions, MySQL would silently truncate or convert invalid values, which could hide data quality issues. When working with DECIMAL types, be aware of precision and scale constraints—a DECIMAL(5,2) can only store values from -999.99 to 999.99. For floating-point comparisons, always use a margin of error rather than exact equality checks, as floating-point arithmetic can introduce rounding errors. Additionally, when migrating data between systems, be mindful that other databases like PostgreSQL handle type coercion differently, potentially masking issues.
ERROR 1064: You have an error in your SQL syntax
How to fix "ERROR 1064: You have an error in your SQL syntax" in MySQL
ERROR 1054: Unknown column in field list
Unknown column in field list
ER_WINDOW_RANGE_FRAME_NUMERIC_TYPE (3589): RANGE frame requires numeric ORDER BY expression
RANGE frame requires numeric ORDER BY expression in MySQL window functions
CR_ALREADY_CONNECTED (2058): Handle already connected
How to fix "CR_ALREADY_CONNECTED (2058): Handle already connected" in MySQL
ER_WINDOW_DUPLICATE_NAME (3591): Duplicate window name
How to fix ER_WINDOW_DUPLICATE_NAME (3591) in MySQL window functions