Answers for "bulk insert mysql from list of tuples"

SQL
0

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()
Posted by: Guest on December-20-2020

Code answers related to "SQL"

Browse Popular Code Answers by Language