MYSQL Truncated incorrect DOUBLE value

后端 未结 10 1860
广开言路
广开言路 2020-12-04 09:11

When the SQL query below is executed:

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


        
相关标签:
10条回答
  • 2020-12-04 09:48

    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
    
    0 讨论(0)
  • 2020-12-04 09:49

    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.

    0 讨论(0)
  • 2020-12-04 09:50

    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.

    0 讨论(0)
  • 2020-12-04 09:53

    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*

    0 讨论(0)
提交回复
热议问题