Can 'false' match some string in mysql?

前端 未结 4 593
夕颜
夕颜 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:23

    If you want to compare a boolean with a varchar, MySQL has to do some implicit type conversion. MySQL casts the varchar value to a boolean, checking only the first character.

    If the character is a character or number 0, then the string is evaluated to 0, thus False.
    If the character is a number different than 0, then the string is evaluted to 1, thus True (and not appearing in your result set)

    The only thing to do is not to compare a string with a boolean, because it makes no sense.

提交回复
热议问题