When I try to run statements like:
cursor.executemany("""INSERT INTO `test` (`id`,`data`,`time_added`)
VALUES (%s, %s, NOW())""", [(i.id, i.data) for i in items])
MySQLdb seems to choke on the ) in NOW(), when it expands the list of rows to be inserted because it sees that parenthesis as the end of the value block. That is, the queries look like:
('1', 'a', NOW(), ('2','b', NOW(), ('3','c',NOW())
And MYSQL reports a syntax error. Instead, they should look like:
('1', 'a', NOW()), ('2','b', NOW()), ('3','c',NOW())
There should be some way to escape the NOW(), but I can't figure out how. Adding 'NOW()' to the tuple doesn't work because then NOW() is quoted and interpreted by the DB as a string rather than a function call.
Working around this by using current timestamp as default value is not an option -- this is an example, I need to do this sort of thing with a variety of db functions, not just now.
Thanks!