use test; DROP TABLE IF EXISTS T1; set @var_0= -1; set @var_1= -1; set @var_1= NULL; set @var_2= CAST(-1 AS SIGNED INTEGER); set @var_3= CAST(NULL AS SIGNED INTEGER); set @var_4= CAST(NULL AS UNSIGNED INTEGER); set @var_5= 'TEXT' ; SELECT @var_0 as f0, @var_1 as f1, @var_2 as f2, @var_3 as f3, @var_4 as f4, @var_5 as f5 ; Catalog Database Table Table_alias Column Column_alias Name Type Length Max length Is_null Flags Decimals Charsetnr def f0 254 20 2 Y 128 31 63 def f1 254 20 0 Y 128 31 63 def f2 254 20 2 Y 128 31 63 def f3 254 8192 0 Y 0 31 8 def f4 254 8192 0 Y 0 31 8 def f5 254 8192 4 Y 0 31 8 # As you see the metadataoutput of the (numeric with content NULL) uservariables @var_3, @var_4 # is similar to @var_5, which was filled with text. But their metadataoutput should equal @var_1. f0 f1 f2 f3 f4 f5 -1 NULL -1 NULL NULL TEXT # The written content of the uservariables looks harmless. Therefore the bug looks on the first view not very important. CREATE TABLE T1 AS SELECT @var_0 as f0, @var_1 as f1, @var_2 as f2, @var_3 as f3, @var_4 as f4, @var_5 as f5 ; SHOW CREATE TABLE T1; Table Create Table T1 CREATE TABLE `T1` ( `f0` bigint(20) default NULL, `f1` bigint(20) default NULL, `f2` bigint(20) default NULL, `f3` longtext, `f4` longtext, `f5` longtext ) ENGINE=MyISAM DEFAULT CHARSET=latin1 # The not intended structure of T1 (f3 and f4 are NOT of type BIGINT or something similar !!) is the result of # the wrong properties of @var_3 and @var_4 . DROP TABLE T1; CREATE TABLE T1 AS SELECT -1 as f0, CAST(-1 AS SIGNED INTEGER) as f1, CAST(NULL AS SIGNED INTEGER) as f2, CAST(NULL AS UNSIGNED INTEGER) as f3, 'TEXT' as f4; SHOW CREATE TABLE T1; Table Create Table T1 CREATE TABLE `T1` ( `f0` int(1) NOT NULL default '0', `f1` int(1) NOT NULL default '0', `f2` int(0) default NULL, `f3` int(0) unsigned default NULL, `f4` char(4) NOT NULL default '' ) ENGINE=MyISAM DEFAULT CHARSET=latin1 # If we go the direct way the structure of the table looks acceptable. The interesting columns (now) f2 and f3 have # the data type int . # Therefore I speculate the bug is outside of the CAST function and inside of the assignment operation to the uservariable. DROP TABLE T1;