开发者

mysql comparing force BINARY

开发者 https://www.devze.com 2023-01-19 01:15 出处:网络
I have two tables. In one I have column like开发者_运维知识库 INT and in other I have row like VARCHAR where I wait user id or unique id for quest with letters...I want compare if INT = VARCHAR in mys

I have two tables. In one I have column like开发者_运维知识库 INT and in other I have row like VARCHAR where I wait user id or unique id for quest with letters...I want compare if INT = VARCHAR in mysql query. I am using:

BINARY int_row = BINARY varchar_row

is this ok ?


As long as you're comparing only numbers, it won't matter. There will be an implicit conversion anyway so that the varchar and int fields can be compared.

The only problem I can think of is if the varchar field can contain values like this:

1ABCDEFGHIJK

you may get into trouble here, because a conversion of this varchar into a number would result in 1!

To make sure, I would tend to use

BINARY CAST(int_row AS CHAR) = BINARY varchar_row

but this can be overly paranoid - correct me if I'm wrong.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号