MySQL Forums
Forum List  »  Connector/Python

Bulk insert query : executemany vs execute(multi = True)
Posted by: Mythri Manjunath
Date: December 12, 2017 02:39AM

Which is more efficient executemany or execute(multi=True) for bulk insert query?

operation = 'INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9)
(11,22,33),(44,55,66)(77,88,99);
INSERT INTO tb2_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);
INSERT INTO employees (first_name, hire_date) VALUES ('Jane',
'2005- 02-12'), ('Joe', '2006-05-23'), ('John', '2010-10-03')'

for result in cursor.execute(operation, multi=True):
print (result.rowcount)

or

data = [
('Jane', date(2005, 2, 12)),
('Joe', date(2006, 5, 23)),
('John', date(2010, 10, 3)),
]
stmt = "INSERT INTO employees (first_name, hire_date) VALUES (%s, %s)"
cursor.executemany(stmt, data)

data2 = [
('Jane', date(2005, 2, 12)),
('Joe', date(2006, 5, 23)),
('John', date(2010, 10, 3)),
]
stmt1 = "INSERT INTO table1 (first_name, hire_date) VALUES (%s, %s)"
cursor.executemany(stmt1, data2)

Options: ReplyQuote


Subject
Written By
Posted
Bulk insert query : executemany vs execute(multi = True)
December 12, 2017 02:39AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.