MySQL 选择不需要的记录时,我遇到了一个非常奇怪的问题。这是我应该重现该问题的设置。
桌子
CREATE TABLE `users` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`uuid` varchar(36) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
记录
INSERT INTO `users` (`id`, `uuid`)
VALUES
(4, '23ee7c80-ce43-11e2-84b8-da3b984baf8c'),
(12, '4bde3afe-ce30-11e2-9e98-b27639b9f5a0');
查询
SELECT * FROM `users` WHERE `users`.`id` = '4bde3afe-ce30-11e2-9e98-b27639b9f5a' LIMIT 1;
结果
+----+--------------------------------------+
| id | uuid |
+----+--------------------------------------+
| 4 | 23ee7c80-ce43-11e2-84b8-da3b984baf8c |
+----+--------------------------------------+
1 row in set, 1 warning (0.00 sec)
如您所见,它选择了错误的记录。任何见解将不胜感激。
编辑
感谢您的输入。事实证明,这是类型转换对我耍花招!这是 MySQL 给出的警告:
mysql> SHOW WARNINGS;
+---------+------+-------------------------------------------------------------------------+
| Level | Code | Message |
+---------+------+-------------------------------------------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: '4bde3afe-ce30-11e2-9e98-b27639b9f5a' |
+---------+------+-------------------------------------------------------------------------+
1 row in set (0.01 sec)
希望我想早点检查一下,但是我的客户端程序(Sequel Pro)没有注册警告,只有错误..哦,好吧