MySQL
Double Value Error
Database Errors
SQL Troubleshooting
Data Truncation

MySQL error: Truncated incorrect DOUBLE value

Codemia Knowledge Hub ·

MySQL raises "Truncated incorrect DOUBLE value" when it has to convert a non-numeric string to a DOUBLE and cannot do it exactly. MySQL keeps only the leading numeric part (so a string like 'abc' becomes 0) and reports the warning. The fix is to stop MySQL from implicitly converting strings: compare and store numbers as numbers, and validate or cast values first.

What DOUBLE is

DOUBLE is MySQL's floating-point numeric type. It stores large numbers with fractional parts and suits work such as scientific calculations.

What triggers the warning

  1. Implicit conversion: MySQL converts non-numeric string data to a number, for example in arithmetic.
  2. Comparisons: a numeric comparison involves a non-numeric string.
  3. Inserts: a non-numeric string is inserted into a DOUBLE column without conversion or validation.

How each case plays out

Arithmetic: multiplying the string 'abc' by a DOUBLE value (1.5) makes MySQL try to convert 'abc' to a number. Because 'abc' is not a valid numeric string, the result is 0 with the warning "Truncated incorrect DOUBLE value: 'abc'".

sql
SELECT 'abc' * 1.5;   -- 0
SELECT '12abc' * 1.5; -- 18 (leading 12 kept)
SHOW WARNINGS;        -- 1292 Truncated incorrect DOUBLE value: '12abc'

Comparison: MySQL tries to convert a string such as 'cheap' to a DOUBLE to perform the comparison. Non-numeric strings convert to 0, so MySQL issues the warning. In an UPDATE or DELETE under strict mode, the same conversion is an error instead of a warning.

sql
1CREATE TABLE products (id INT, price DOUBLE, label VARCHAR(20));
2INSERT INTO products VALUES (1, 9.99, 'cheap'), (2, 50, '123.45');
3
4SELECT * FROM products WHERE price < 'cheap';
5-- Warning 1292: Truncated incorrect DOUBLE value: 'cheap'
6
7UPDATE products SET price = 1 WHERE label = 0;
8-- ERROR 1292 (22007): Truncated incorrect DOUBLE value: 'cheap'

Insert: inserting 'alpha' into a DOUBLE column fails to convert. Strict mode (the default) rejects the row; without strict mode MySQL stores 0 with a warning.

sql
INSERT INTO products (id, price) VALUES (3, 'alpha');
-- ERROR 1265 (01000): Data truncated for column 'price' at row 1

Explicit casting: casting explicitly, guarded by a condition, ensures only valid conversions are attempted, so a value such as '123.45' is correctly interpreted as a DOUBLE.

sql
1SELECT id, CAST(label AS DOUBLE) AS label_num
2FROM products
3WHERE label REGEXP '^-?[0-9]+(\\.[0-9]+)?$';
4-- id 2, label_num 123.45

Preventing it

  • Validate data types in the application before sending them to MySQL.
  • Enable MySQL's strict mode so these warnings are not silently ignored.
  • Use the right column types: if a column stores non-numeric data, do not give it a numeric type.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design