MYSQL Truncated incorrect DOUBLE value

后端 未结 10 1878
广开言路
广开言路 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: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*

提交回复
热议问题