I have following code to insert multiple rows;
cnx = pymysql.connect(host='xx', user='xx', password='xx', database='xx', autocommit=True)
cursor = cnx.cursor()
query = "INSERT INTO `tableA`('id,'name',...)values(?,? ......)"
cursor.executemany(query, listTosave)
My listTosave contains values like;
[['AS0001', '1170', 1, '1', 'Unknown', 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), Decimal('15177.3184'), Decimal('15185.7562'), Decimal('8.4378')],[......],...
....]]
When I try to insert I get following error;
cursor.executemany(query, listTosave)
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
What am I doing wrong here? I would like to insert multiple rows at once.
listTosave
should be an list of tuples rather than list of lists
[('AS0001', '1170', 1, '1', 'Unknown', 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), Decimal('15177.3184'), Decimal('15185.7562'), Decimal('8.4378')),(......),...]