Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

MySQL error 1292 on a statement that compares text with a number

ErrorERROR 1292 (22007): Truncated incorrect DOUBLE value: 'grape'

Short answer

MySQL compares a string with a number by turning both into floating-point numbers. A non-numeric string such as grape cannot be converted cleanly, and in strict mode a data-change statement fails with error 1292. Quote the number so it is compared as text, or cast one side on purpose.

  • Applies to MySQL 8.4
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Read the value inside the quotes in the error. It is the string MySQL tried to turn into a number, and it points at the column in your condition.

    SHOW WARNINGS;
  2. 2Match what you see, then jump to its fix

    1. 1The quoted value in the error is a word from a VARCHAR column, and the condition is col = 0 or col = 5A text column is compared with a numberFix
    2. 2Both sides are columns, for example orders.ref (VARCHAR) joined to items.id (INT), and the quoted value in the error is not a numberA JOIN or condition compares a text column with a numeric columnFix

What does the error look like?

  • ERROR 1292 (22007): Truncated incorrect DOUBLE value: 'grape'

Cause 1 of 2

A text column is compared with a number

1Check

Look at the types of both sides of every comparison in the WHERE and ON clauses.

SHOW COLUMNS FROM fruit;

2Fix

Write the literal as a string when the column is text. In a plain SELECT the same mistake only gives warnings, and the manual notes the result: a non-numeric string like 'x6' becomes 0, so it equals 0.

-- fails with error 1292 when c3 is a VARCHAR
CREATE TABLE fruit2 SELECT * FROM fruit WHERE c3 = 0;
-- compares text with text
CREATE TABLE fruit2 SELECT * FROM fruit WHERE c3 = '0';

3Verify

The statement runs and copies only the rows you expected.

SELECT * FROM fruit WHERE c3 = '0';

Confirmed by dev.mysql.com

Did this fix it?

Cause 2 of 2

A JOIN or condition compares a text column with a numeric column

1Check

Mixed types make MySQL compare as floating point, and it cannot use the index on the string column. List the column types of both tables.

SHOW COLUMNS FROM orders;
SHOW COLUMNS FROM items;

2Fix

Make the types match. If you cannot change the schema, cast the text side, but only when every value in it is digits: a non-numeric value still converts to 0.

UPDATE orders o JOIN items i ON CAST(o.ref AS UNSIGNED) = i.id
SET o.item_name = i.name;

3Verify

The statement no longer reports error 1292.

SHOW WARNINGS;

Confirmed by dev.mysql.com

Did this fix it?

How do I stop it coming back?

  • Give columns that join each other the same type.
  • Always quote string literals, even when they look like numbers.
  • Run a SELECT with the same WHERE before every UPDATE or DELETE, and read the warnings.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.