Jack_90 Jack_90 - 1 month ago 16
MySQL Question

Updating varchar has no effect

I want to update a varchar column with the update clause like this:

UPDATE ptl SET version=NULL WHERE version = 'a';


and MySQL gives me this answer:

Query OK, 0 rows affected


I have several entries where the version is 'a' like for example this one:

Title version
Hiper a


And after my update statement it should turn into following:

Title version
Hiper NULL


but it does stay the same.

Why does it not change?

Answer

What looks like an "a" would not seem to be solely an 'a'. This can be for a variety of reasons. Start with:

select length(ptl.version), ptl.version 
from ptl
where version like '%a%'
order by length(ptl.version);

You can see the length of the version being returned.

You might have other characters such as spaces in the value. Or, you might have a utf character that happens to look like a lower-case a. In the latter case, the above may not return anything.