MYSQL Truncated incorrect DOUBLE value

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

    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.

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

    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.

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

    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.

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

    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.

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

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

    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;
    
    0 讨论(0)
提交回复
热议问题