Can 'false' match some string in mysql?

前端 未结 4 642
夕颜
夕颜 2021-01-21 15:48

I have a table like this:

CREATE TABLE IF NOT EXISTS `session` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `token` varchar(32) NOT NULL,
  `profile` varchar(1000         


        
4条回答
  •  误落风尘
    2021-01-21 16:21

    In MYSQL, FALSE is not a boolean value, it's an integer, more specifically zero. In fact, MySQL does not have boolean column types (it has BOOL and BOOLEAN but they're mere aliases for TINYINT). So your query is a synonym for:

    SELECT * FROM session WHERE token = 0
    

    Since token is a VARCHAR, MySQL needs to convert your strings to number. Run this query and you'll get an idea about the rules:

    SELECT
        0 + "0001",
        0 + "123abc",
        0 + "abc123"
    

    As a result, fa356333dd3ee8f1b18b8bf0a827e34c casts to 0 because it starts with a letter, thus the match.

提交回复
热议问题