insert multiple rows sql python code example
Example: bulk insert mysql from list of tuples
#function to transform your list into a string
def stringify(v):
return "('%s', '%s', %s, %s)" % (v[0], v[1], v[2], v[3])
#transform all to string
v = map(stringify, row)
#glue them together
batchData = ", ".join(e for e in v)
#complete the SQL
sql = "INSERT INTO `table_name`(`column`, `column_1`, `column_2`, `column_3`) \
VALUES %s" % batchData
#execute it
cursor.execute(sql)
db.commit()