Casting varchar for int in mysql

I have an air_id column, which is a varchar in the route of the table, now I want to copy this value to the air_id_int column, which is of type int. I cannot get the syntax correctly, though ..

This is what I have:

UPDATE route SET airline_id_int = CAST(airline_id, int);
+4
source share
4 answers

For CAST, you need to use the AS keyword .

update route set airline_id_int = cast(airline_id AS UNSIGNED)

you can use

update route set airline_id_int = cast(airline_id AS SIGNED)

.

+9
source

Try the following:

update route set airline_id_int = cast(airline_id AS UNSIGNED);

Cannot pass value directly int. If you need a signed int, replace UNSIGNEDwith SIGNED.

+3
source
update route set airline_id_int = cast(airline_id as signed);

or

update route set airline_id_int = cast(airline_id as unsigned);

if it can be negative

+1
source

try it

update route set airline_id_int = CONVERT(airline_id, UNSIGNED);
update route set airline_id_int = CONVERT(airline_id, SIGNED);
0
source

All Articles