今天的故事是我得到了一些错误的结果,我找到了空洞日的原因
原因是我试图使用 BIGINT id 来等于 VARCHAR(64) id。
错误的SQL是:
select t1.id,t1.name,
t2.id,t2.name
from location t1
left join location t2 on t2.parent_id = t1.id
where id = 1649972899018952705
我不知道这个表是谁创建的,但事实是id的类型是BIGINT,parent_id的类型是VARCHAR(64)。
但是为什么?我试过这些:
select 1649972899018952705 = '1649972899018952706' # returns 1
select 164997289901895270 = '164997289901895271' # returns 1
select 164997289901895271 = '164997289901895261' # returns 1
select 16499728990189527 = '164997289901895261' # returns 0
select 164997289901895271 = '16499728990189526' # returns 0
select 16499728990189527 = '16499728990189526' # returns 0
select 1 = '2' # returns 0
我猜MySQL会改变'1649972899018952706'或1649972899018952705的类型来操作,但是参数是怎么改变的,好像MySQL会截断它们。
我可以通过使用不同的 MySQL 版本得到不同的结果吗?