Converting text to tinyint in MYSQL

3.3k Views Asked by At

By now, I understood there is no BOOLEAN type in mysql and internally it converts to tinyint(1) when the datatype is boolean. But I also came across that tinyint is not being handled by CAST or CONVERT function.

So basically my question is is there any direct way to typecast the datatype to TINYINT(1) the way it can be handled for any other data like DATE.

Examples :

select cast(column_name as DATE) -- Works 

select cast(column_name as tinyint) -- Doesn't work

So how can I simply convert the type to tinyint(1) without altering the table ..

1

There are 1 best solutions below

2
Bill Karwin On

Did you read the documentation for CAST() and CONVERT()?

Those functions don't support all data types. They will not cast or convert to TINYINT. The closest data type you can cast or convert to is an INTEGER (either SIGNED or UNSIGNED).