Here is the call signature for cursor.execute:
Definition: cursor.execute(self, query, args=None)
query -- string, query to execute on server
args -- optional sequence or mapping, parameters to use with query.
Thus, execution expects no more than 3 arguments (arguments are optional). If arguments are given, it is expected to be a sequence. So
sql_and_params = "INSERT INTO table VALUES (%s, %s, %s)", var1, var2, var3
cursor.execute(*sql_and_params)
will not work because
cursor.execute(*sql_and_params)
extends the tuple sql_and_params by 4 arguments (and only 3 are executed again).
sql_and_params = "INSERT INTO table VALUES (%s, %s, %s)", var1, var2, var3
cursor.execute:
cursor.execute(sql_and_params[0],sql_and_params[1:])
, :
sql = "INSERT INTO table VALUES (%s, %s, %s)"
args= var1, var2, var3
cursor.execute(sql, args)