gpt4 book ai didi

MySql 奇怪的行为 - 从 where 子句中的 id 右侧去除字符

转载 作者:行者123 更新时间:2023-11-30 22:12:34 27 4
gpt4 key购买 nike

今天我发现了一些奇怪的事情。假设你有一个 mysql 表:

create table usr(
usr_id serial
)

然后你插入一行:

INSERT INTO usr (usr_id) VALUES ('1');

然后你运行一个查询:

SELECT * FROM usr WHERE usr_id='1sfgfsdgs'

MySql 返回结果,就像您输入的一样:

SELECT * FROM usr WHERE usr_id='1'

这应该发生吗??如果是 - 有人可以指点我描述这个的文档吗?我只是想知道这是否是预期的行为。

[jeremy@jjxps15 ~]$ mysql --versionmysql Ver 15.1 Distrib 10.1.17-MariaDB,适用于使用 readline 5.1 的 Linux (x86_64)

最佳答案

好吧,这是有污垢的页面,http://dev.mysql.com/doc/refman/5.7/en/type-conversion.html

但清澈如泥

When an operator is used with operands of different types, type conversion occurs to make the operands compatible. Some conversions occur implicitly. For example, MySQL automatically converts numbers to strings as necessary, and vice versa.

它确实有几个例子让事情更清楚一些

mysql> SELECT 1 > '6x';
-> 0
mysql> SELECT 7 > '6x';
-> 1
mysql> SELECT 0 > 'x6';
-> 0
mysql> SELECT 0 = 'x6';
-> 1

这实质上意味着,如果将一个数字与一个字母数字字符串进行比较,并且该字符串以数字开头,则所有结尾的非数字字符都将被丢弃。

您使用 serial 的事实与此没有任何关系。

关于MySql 奇怪的行为 - 从 where 子句中的 id 右侧去除字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39593810/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com