According to psycopg2: insert multiple rows with one query, it is much more efficient to use psycopg2's execute instead of executemany . Can others confirm?
The above StackOverflow question suggests using mogrify for creating statements of the sort:
INSERT INTO table VALUES (value1, value2), (value3, value4)
Is it possible to generate such a statement using the regular execute function? I thought something of the form
cursor.execute("""INSERT INTO table VALUES (%s, %s), (%s, %s)""", ((value1,value2),(value3,value4)))
would work.
UPDATE:
For instance, I tried I passing into execute the sql statement:
insert into history (timestamp) values (%s),(%s);
with the folowing tuple:
(('2014-04-27 14:07:30.000000',), ('2014-04-27 14:07:35.000000',))
but all I got back was the error:
no results to fetch