不希望 mysql 将 String 自动转换为 Integer [英] Don't want mysql to auto cast String to Integer

查看:51
本文介绍了不希望 mysql 将 String 自动转换为 Integer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现这种从字符串到整数的 MYSQL 自动类型转换在我看来很奇怪.

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-19ce56349ad6' OR `unique_id` = '3ca6fb49-9749-3099-b30d-19ce56349ad6';
+----+--------------------------------------+---------------+--------------+---------------------+---------------------+
| id | unique_id                            | name          | code         | created_at          | updated_at          |
+----+--------------------------------------+---------------+--------------+---------------------+---------------------+
|  3 | ee8db3be-1bf7-3440-8add-37232cfc4ecb | TTN           | ttn          | 2019-09-26 08:12:14 | 2019-09-26 08:12:14 |
|  7 | 3ca6fb49-9749-3099-b30d-19ce56349ad6 | ONE BROADBAND | onebroadband | 2019-09-26 08:12:14 | 2019-09-26 08:12:14 |
+----+--------------------------------------+---------------+--------------+---------------------+---------------------+

我没有预料到 id = 3 的结果,谁能帮忙解决这个问题.

I had not expected result with id = 3 can anyone help with this.

id - BIGINT
unique_id - varchar(200)

推荐答案

您可以在比较之前将 id 转换为字符串.

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';

请注意,这会显着减慢查询速度,因为它将无法使用 id 列上的索引.

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

这篇关于不希望 mysql 将 String 自动转换为 Integer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆