Quantcast
Channel: MySQL Forums - Connector/Python
Viewing all articles
Browse latest Browse all 384

Bulk insert query : executemany vs execute(multi = True) (no replies)

$
0
0
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)

Viewing all articles
Browse latest Browse all 384

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>