When I use the executemany function with a mysql function in the values, the call fails. For example:
INSERT INTO invoice_item (invoice_id, sku_id, invoice_item_qty, invoice_item_added_date)
VALUES (%s, %s, %s, NOW() )""",
where stmt is a list of lists with 3 values in each sub-list (e.g, [(26L, 1L, 1), (26L, 7L, 7), (26L, 10L, 6600)] ).
The relevant traceback is as follows
File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 218, in executemany
r = self._query('\n'.join([query[:p], ',\n'.join(q), query[e:]]))
File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 312, in _query
rowcount = self._do_query(q)
File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 276, in _do_query
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 6")
When I replace NOW() with CURRENT_TIMESTAMP, everything works as expected.
Note, I have used NOW() successfully with the execute function:
INSERT into invoice (cust_id, invoice_amt_due, invoice_created_date)
VALUES (%s, %s, NOW())""",
Using ubuntu 10.04LTS, mysqldb 1.2.2 with python 2.6.
Log in to post a comment.