Skip to content
Advertisement

Issue with cast function in update query

Here is a simple table and test data that I will use to demonstrate my issue:

I would like to update some fields with a query like this:

However I get the error

I understand that by removal of a CAST query will work but I would like to understand why is this operation not permitted?

MySQL is 5.6 Here is the link to fiddle http://sqlfiddle.com/#!9/420d7f

Advertisement

Answer

It’s true you don’t need to use CAST() in this case.

But for the record, the error is because you’re using INTEGER in a position where it is not supported by the syntax.

OK:

WRONG:

See documentation for CAST() and CONVERT() to read about the supported data type syntax: https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement