如何在Python中为MySQL设置空值
这是我的SQL命令行版本如何在Python中为MySQL设置空值,python,mysql,python-2.7,null,mysql-python,Python,Mysql,Python 2.7,Null,Mysql Python,这是我的SQL命令行版本 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 122 Server version: 5.0.95 Source distribution 我有一个表,在Python中,我想把最后一列写为null。最后,特定行的最后一列将获得一个日期戳,我将使用它作为不再处理该行的标志 +---------------+-------------+------
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 122
Server version: 5.0.95 Source distribution
我有一个表,在Python中,我想把最后一列写为null。最后,特定行的最后一列将获得一个日期戳,我将使用它作为不再处理该行的标志
+---------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| Action | char(1) | NO | | R | |
| EndpointId | int(11) | NO | MUL | NULL | |
| DeviceType | smallint(6) | NO | | NULL | |
| ChannelNumber | smallint(6) | NO | | 0 | |
| ActionDate | date | YES | | NULL | |
| InsertDate | date | YES | | NULL | |
+---------------+-------------+------+-----+---------+-------+
如何在insert查询字符串中输入null?换句话说,我不知道如何在Python查询字符串中表示NULL
sql_cmd = \
"""insert into cs_remove
(
Action, EndpointId, DeviceType, ChannelNumber, ActionDate, InsertDate
)
VALUES
(
%s, %s, %s, %s, %s, %s
)
"""
print(base_date)
sql_data = ('R', ept_id, ept_type, ept_ch, "NULL", base_date);
该示例最后将0000-00-00放入日期字符串中。我要空的。我可以从mysql命令行执行此操作,但不能从Python执行。任何帮助都将不胜感激。您应该使用python中的
None
值来表示您尝试插入的NULL
mysql值。像这样:
sql_data = ('R', ept_id, ept_type, ept_ch, base_date, None);
以下是另一篇有此问题的帖子:
以及这篇文章:试着使用
None
。我感觉可能没有。我去试试这个。谢谢