According to this answer, the correct way to build a Parameterized SQL Statement that will be safe is by using a tuple to string format the query like this:
cursor.execute("INSERT INTO table VALUES (%s, %s, %s)", (var1, var2, var3))
However, in my case the values are stored in an array where the length can vary. I'm trying to create the Parameterized SQL Statement like below, but I have a syntax error that I don't understand:
values = ["a", "b", "c", "d"]
cursor.execute("INSERT INTO table VALUES ({})".format(",".join(u"%s", (v,) for v in values)))
>>>SyntaxError: Generator expression must be parenthesized if not sole argument
Expected result:
"INSERT INTO table VALUES (%s, %s, %s, %s)"
What would be the correct way to achieve this?