Varchar seems casted to integer somehow in MySQL

38 views Asked by At

I have the following column definition:

col varchar(8) not null

It contains ONLY h and w values:

col
h
h
w
w
w
h

The problem is that doing the following query:

SELECT * FROM t WHERE t.col = 0 limit 100;

Gives me some results, while it shouldn't. It's integer, not varchar. What's happening? Also, what happens if I insert 0 as integer to such column?

EDIT:

It's NDB cluster table. Full table definition:

CREATE TABLE `graph` (
  `id` bigint(20) unsigned NOT NULL,
  `neighbor` bigint(20) unsigned NOT NULL,
  `type` varchar(8) NOT NULL,
  PRIMARY KEY (`id`,`neighbor`,`type`)
) ENGINE=ndbcluster DEFAULT CHARSET=utf8;

Sample data:

id | neighbor | type
1    1          h
2    1          h
3    2          w

Sample SQL:

select * from graph g where g.type = 0;

Sample output:

id | neighbor | type
1    1          h
2    1          h
3    2          w

While select * from graph g where g.type = 1; returns an empty set.

0

There are 0 answers