189

When the SQL query below is executed:

UPDATE shop_category 
SET name = 'Secolul XVI - XVIII' 
    AND name_eng = '16th to 18th centuries' 
WHERE category_id = 4768

The following error is raised:

1292 - Truncated incorrect DOUBLE value: 'Secolul XVI - XVIII'

How to fix this?


shop_category table structure:

category_id   mediumint(8)
name        varchar(250)
name_eng      varchar(250)
Braiam
  • 1
  • 11
  • 47
  • 78
Emanuel
  • 6,622
  • 20
  • 58
  • 78
  • 2
    Is it in any way determinable what the real meaning of this error message is, and in which cases it shows up? Since it occurs in contexts where a DOUBLE value is not involved, it seems somewhat misleading. – syck Mar 28 '17 at 10:04
  • 1
    Guess it tries to calculate BOOLEAN value of 'Secolul XVI - XVIII' before AND. – Anton Kolyaev Mar 07 '18 at 10:54
  • 2
    If you have "where x = 'x' and y" you will get this poorly conceived and obscure error – Johan Snowgoose Oct 03 '18 at 19:28

14 Answers14

272

You don't need the AND keyword. Here's the correct syntax of the UPDATE statement:

UPDATE 
    shop_category 
SET 
    name = 'Secolul XVI - XVIII', 
    name_eng = '16th to 18th centuries' 
WHERE 
    category_id = 4768
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
89

I was getting this exception not because of AND instead of comma, in fact I was having this exception just because I was not using apostrophes in where clause.

Like my query was

update table set coulmn1='something' where column2 in (00012121);

when I changed where clause to where column2 in ('00012121'); then the query worked fine for me.

Mihai Iorga
  • 39,330
  • 16
  • 106
  • 107
Sidra
  • 891
  • 6
  • 2
  • 2
    Same issue for me! I was trying to update a table in a crm that uses 1 as the user id of admin user and 36 char guids for all other users. My where was specifying the user_id as 1, without the quotes. I think this is related to mysql being in strict mode. – dmulvi Apr 25 '13 at 22:49
  • 3
    @danny_mulvihill I believe you are on the right track. I had `STRICT_TRANS_TABLES` set in `sql_mode` and attempting to update a field limited with (what appeared to be) a numeric value in the `where` clause threw an error. Changing modes, it threw a warning instead, but still did not apply the update. Upon closer inspection, the column used in the where clause, despite only having what appeared to be integer values, was actually a `varchar(20)` – Robert Gannon Jul 30 '14 at 13:54
  • Same issue for me. A 'select * from t where id = 6503' worked okay but 'update t set a = "foo" where id = 6503' resulted in ERROR 1292 (22007): Truncated incorrect DOUBLE value: '234805557438#'. id looks like integer but was a varchar. Quoting the value in the update solved the problem. 'update t set a = "foo" where id = "6503"' – gaoithe Mar 24 '16 at 11:33
  • Same issue for me when passing a INSERT that was working in mysql console but wasn't working in Pentaho Data Integration software. Changed "name > 1000 and name < 6000" to "name > '1000' and name < '6000'" and worked like a charm. – Sawd Dec 06 '16 at 20:01
31

What it basically is

It's incorrect syntax that causes MySQL to think you're trying to do something with a column or parameter that has the incorrect type "DOUBLE".

Learn from my mistake

In my case I updated the varchar column in a table setting NULL where the value 0 stood. My update query was like this:

UPDATE myTable SET myValue = NULL WHERE myValue = 0;

Now, since the actual type of myValue is VARCHAR(255) this gives the warning:

+---------+------+-----------------------------------------------+
| Level   | Code | Message                                       |
+---------+------+-----------------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: 'value xyz' |
+---------+------+-----------------------------------------------+

And now myTable is practically empty, because myValue is now NULL for EVERY ROW in the table! How did this happen?
*internal screaming*

Over 30k rows now have missing data.
*internal screaming intensifies*

Thank goodness for backups. I was able to recover all the data.
*internal screaming intensity lowers*

The corrected query is as follows:

UPDATE myTable SET myValue = NULL WHERE myValue = '0';
                                                  ^^^
                                                  Quotation here!

I wish this was more than just a warning so it's less dangerous to forget those quotes.

*End internal screaming*

halfpastfour.am
  • 5,764
  • 3
  • 44
  • 61
15

Try replacing the AND with ,

UPDATE shop_category 
SET name = 'Secolul XVI - XVIII', name_eng = '16th to 18th centuries' 
WHERE category_id = 4768

The UPDATE Syntax shows comma should be used as the separator.

codaddict
  • 445,704
  • 82
  • 492
  • 529
8

I just wasted my time on this and wanted to add an additional case where this error presents itself.

SQL Error (1292): Truncated incorrect DOUBLE value: 'N0003'

Test data

CREATE TABLE `table1 ` (
    `value1` VARCHAR(50) NOT NULL 
);
INSERT INTO table1 (value1) VALUES ('N0003');

CREATE TABLE `table2 ` (
    `value2` VARCHAR(50) NOT NULL 
);

INSERT INTO table2 (value2)
SELECT value1
FROM table1
WHERE 1
ORDER BY value1+0

The problem is ORDER BY value1+0 - type casting.

I know that it does not answer the question but this is the first result on Google for this error and it should have other examples where this error presents itself.

hrvoj3e
  • 2,512
  • 1
  • 23
  • 22
6

Mainly invalid query strings will give this warning.

Wrong due to a subtle syntax error (misplaced right parenthesis) when using INSTR function:

INSERT INTO users (user_name) SELECT name FROM site_users WHERE
INSTR(status, 'active'>0);

Correct:

INSERT INTO users (user_name) SELECT name FROM site_users WHERE
INSTR(status, 'active')>0;
Adrian Goia
  • 151
  • 3
  • 7
  • I had an interesting situation that was similar to this. Someone had used "select Field + Field2" instead of "select concat(Field,Field2)" on an insert statement. – AnthonyJ Sep 08 '21 at 23:29
6

It seems mysql handles the type casting gracefully with SELECT statements. The shop_id field is of type varchar but the select statements works

select * from shops where shop_id = 26244317283;

But when you try updating the fields

update stores set store_url = 'https://test-url.com' where shop_id = 26244317283;

It fails with error Truncated incorrect DOUBLE value: '1t5hxq9'

You need to put the shop_id 26244317283 in quotes '26244317283' for the query to work since the field is of type varchar not int

update stores set store_url = 'https://test-url.com' where shop_id = '26244317283';
Winnipass
  • 904
  • 11
  • 22
5

This is because of "and" in-between while using update query

WRONG ==> "update user_detail set name = ? and phone_code = ? and phone_num = ? and email = ? where emp_code = ?";

instead of this use COMMA(,)

RIGHT ==> "update user_detail set name = ?, phone_code = ?, phone_number = ?, email = ? where emp_code = ?"

CodingBee
  • 1,011
  • 11
  • 8
4

1292 - Truncated incorrect DOUBLE value:

This error occurs when you try to compare different types on SQL like `uniqueid` = 1610386969.1713 in this query:

UPDATE `cdr` SET `userfield`='survey=5,' WHERE `uniqueid` = 1610386969.1713

change it for passing the error on this UPDATE example:

UPDATE `cdr` SET `userfield`='survey=5,' WHERE `uniqueid` = '1610386969.1713'

But in your problem, if you change the AND to , the problem will be resolved

UPDATE shop_category SET name = 'Secolul XVI - XVIII', name_eng = '16th to 18th centuries' WHERE category_id = 4768
Pejman Kheyri
  • 4,044
  • 9
  • 32
  • 39
0

If you're getting this problem with an insert that looks like the one below, the problem may simply be the lack of a space between -- and the comment text:

insert into myTable (a, b, c)
values (
   123 --something
  ,345 --something else
  ,567 --something something else
);

The problem with this is that the --something should actually be -- something with a space.

Joe Phillips
  • 49,743
  • 32
  • 103
  • 159
0

I experienced this error when using bindParam, and specifying PDO::PARAM_INT where I was actually passing a string. Changing to PDO::PARAM_STR fixed the error.

Bytech
  • 1,125
  • 7
  • 22
0

I did experience this error when I tried doing an WHERE EXIST where the subquery matched 2 columns that accidentially was different types. The two tables was also different storage engines.

One column was a CHAR (90) and the other was a BIGINT (20).

One table was InnoDB and the other was MEMORY.

Part of query:

[...] AND EXISTS (select objectid from temp_objectids where temp_objectids.objectid = items_raw.objectid );

Changing the column type on the one column from BIGINT to CHAR solved the issue.

thephper
  • 2,342
  • 22
  • 21
0
// CALL `ut_liquid_name_maildt`() Edit
// Truncated incorrect DOUBLE value: 'IPPAGUNTA VIJAYALAKSHMI'

// Code Sample

BEGIN

 -- Declare loop constructs --
    DECLARE done INT DEFAULT FALSE; 
    DECLARE my_id VARCHAR(50);
    DECLARE my_name VARCHAR(50);
    DECLARE my_mail_dt date;
    DECLARE my_name_gl VARCHAR(50);
    DECLARE my_mail_dt_gl VARCHAR(50);
  

-- cursor --
declare cr cursor for select t2.id,t1.name,t1.mail_dt,t2.name as name_gl,t2.mail_dt as mail_dt_gl
from sch_acc_saleint as t1
inner join
sch_acc_salegl  as t2 
where t1.sch_batch = t2.sch_batch;

 -- Declare Continue Handler --
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

OPEN cr;

    read_loop: LOOP

        -- Fetch data from cursor --
        FETCH cr 
        INTO my_id,my_name,my_mail_dt,my_name_gl,my_mail_dt_gl;

       -- Exit loop if finished --
        IF done THEN
            LEAVE read_loop;
        END IF;
        -- Update Query --
        UPDATE sch_acc_salegl SET name = my_name and mail_dt = my_mail_dt  WHERE id = my_id;


    END LOOP read_loop;

CLOSE cr;

END

// I was using wrong update query that"s why it is showing error [ Truncated incorrect DOUBLE value ]
// For this type of error check update query
// For example :

UPDATE sch_acc_salegl SET name = my_name,mail_dt = my_mail_dt  WHERE id = my_id;
Sonu Chohan
  • 141
  • 1
  • 5
0

In my case it was a Dreamweaver function that sanitizes the data before running mysql queries:

GetSQLValueString($my_string, "text")

by mistake I had it as:

GetSQLValueString($my_string, "int")

Basically converting my string to an integer then trying to run MySQL queries based on that. When it should have been a string.

So using "int" instead of "text" caused the problem for me.

adrianTNT
  • 3,671
  • 5
  • 29
  • 35