Don't want mysql to auto cast String to Integer

后端 未结 1 1093
醉酒成梦
醉酒成梦 2021-01-28 13:12

I came across this auto typecasting of MYSQL from String to Integer seems to me weird.

mysql> select * from `isps` where `id` = \'3ca6fb49-9749-3099-b30d-19ce         


        
相关标签:
1条回答
  • 2021-01-28 13:23

    You can cast id to a string before comparing.

    select * from `isps` where CAST(`id` AS CHAR) = '3ca6fb49-9749-3099-b30d-19ce56349ad6' OR `unique_id` = '3ca6fb49-9749-3099-b30d-19ce56349ad6';
    

    Note that this will slow down the query significantly, since it won't be able to use the index on the id column.

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