且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将NULL值插入双精度数据类型MySQL Python

更新时间:2023-02-13 17:32:55

这并不完全令人惊讶.在第一个实例中,您要插入python预定义常量

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

types.NoneType的唯一值.没有一个经常被用来表示 缺少值,例如默认参数未传递给 功能.

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.

等同于SQL NULL.在第二个实例中,您将在表中插入一个名为"None"的字符串.这两个是非常不同的.如果将字符串插入double或float字段中,您将看到各种错误,大多数情况下,就是您所看到的错误.

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` double DEFAULT NULL,

这接受NULL,并且None在值列表中排在第八位.当使用许多不同的参数时,使用命名参数始终是一个好主意,这样一眼便可以看出绑定到每列的内容.

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.

更新:

运行代码后,唯一可以得出的结论是,您发现了一个错误,使用print(cursor.statement)可以发现执行的查询是.

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.

INSERT INTO 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