Disadvantages of quoting integers in a Mysql query?

后端 未结 4 1255
天涯浪人
天涯浪人 2020-12-06 18:56

I am curious about the disadvantage of quoting integers in MYSQL queries

For example

SELECT col1,col2,col3 FROM table WHERE col1=\'3\';
4条回答
  •  既然无缘
    2020-12-06 19:54

    It gives the wrong impression about the data type for the column. As an outsider, I assume the column in question is CHAR/VARCHAR & choose operations accordingly.

    Otherwise MySQL, like most other databases, will implicitly convert the value to whatever the column data type is. There's no performance issue with this that I'm aware of but there's a risk that supplying a value that requires explicit conversion (using CAST or CONVERT) will trigger an error.

提交回复
热议问题