'Python/MYSQL How do i insert multiple records into a table with unknown number of values?

As the title suggest, i'm struggling to find a way to insert multiple records into a table with an unknown amount of values?

The way that i was taught: sql = "INSERT INTO table_name VALUES(%s,%s,%s)" mycursor.execute(sql, list_of_records)

but obviously this assumes you know how many values that's going to be inserted. I'm wondering if there's another way to do this. I can't find any solution online.



Solution 1:[1]

Use list comprehension

sql = "INSERT INTO table_name VALUES(" + ",".join(["%s" for i in list_of_records]) + ")"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Evyn