我试图在数据库中保存一堆元组
cursor = cnx.cursor()
query = """INSERT INTO `TableA`
(`clientid`,
`createddatetime`,
`siteid`,...)
VALUES(?,?,?,...)"""
cursor.executemany(query, listTosave)
My 保存列表包含元组列表,例如;
[('AS0001', '1170', 1, '1', '未知', 442, 1, datetime.datetime(2018,
5, 28, 23, 0), datetime.datetime(2018, 3, 15, 11, 15),
datetime.datetime(2018, 3, 15, 10, 56), datetime.datetime(2018, 5, 28,
23, 18, 26), datetime.datetime(2018, 5, 28, 23, 59, 22),
十进制('15177.3184'), 十进制('15185.7562'), 十进制('8.4378'),
十进制('1313.0547'), 十进制('1313.6179'), 十进制('0.5632'),
小数('0.0000'),小数('0.0000'),小数('0.0000'),
小数('0.0000'),小数('0.0000'),小数('0.0000'),
十进制('24.6518'), 十进制('24.6518'), 15101.7062, 0.0, 0.0, 0.0,
24.6563), (......... )]
当我尝试保存时,我得到;
File "/tmp/pymodules/pymysql/cursors.py", line 194, in executemany
File "/tmp/pymodules/pymysql/cursors.py", line 194, in <genexpr>
File "/tmp/pymodules/pymysql/cursors.py", line 163, in execute
File "/tmp/pymodules/pymysql/cursors.py", line 142, in mogrify
TypeError: not all arguments converted during string formatting
为什么我会收到此错误?
Edit :我也将日期时间对象/小数对象转换为字符串。我的新清单是这样的;
[('AS0001', '1170', '1', '1', '未知', '442', '1', '2018-05-28
23:00:00', '2018-03-15 11:15:00', '2018-03-15 10:56:00', '2018-05-28
23:18:26', '2018-05-28 23:59:22', '15177.3184', '15185.7562',
'8.4378', '1313.0547', '1313.6179', '0.5632', '0.0000', '0.0000',
'0.0000', '0.0000', '0.0000', '0.0000', '24.6518', '24.6518',
'15101.7062','0.0','0.0','0.0','24.6563'),(.....)]
但我仍然遇到同样的错误