Skip to content Skip to sidebar Skip to footer

Inserting Null Value To A Double Data Type Mysql Python

I have a table. This is the create statement. CREATE TABLE `runsettings` ( `runnumber` mediumint(9) NOT NULL, `equipment` varchar(45) NOT NULL, `wafer` varchar(45) NOT NU

Solution 1:

This is not entirely suprising. In the first instance you are inserting the python predefined constant None

The sole value of types.NoneType. None is frequently used to represent the absence of a value, as when default arguments are not passed to a function.

That equates to SQL NULL. In the second instance you are inserting a String called 'None' into the table. These two are very different. If you insert a string into a double or float field you will see all kinds of errors, most often, the exact one you have seen.

in the first instance it works because you have declared :

 `float8value` doubleDEFAULTNULL,

This accepts NULL and None is in the 8th place in your values list. When lots of different parameters are being used, it's always a good idea to use named parameters so that it's obvious at a glance what's being bound to each column.

Updates:

After running your code, the only conclusion that can be reached is that you have found a bug, by using print(cursor.statement) it's possible to discover that the executed query is.

INSERTINTO runsettings (apcrunid,equipment,runnumber,wafer,settingname,intvalue,floatvalue,float8value) 
VALUES (471285,'CT19',7,'271042','Etch Time Min',NULL,NULL,NULL),
       (471285,'CT19',7,'00000','Etch Time Min',NULL,NULL,'None')

This does not produce an error, but if you erase the first set of values the error is indeed produced. My recommendation is to file a bug report

Post a Comment for "Inserting Null Value To A Double Data Type Mysql Python"