Is it possible to use variables in SQL statement in Python?

0 votes
Suppose there is a statement in SQL "INSERT INTO table VALUES var1, var2, var3," where var1 and var2 are strings and var3 is an integer. So now my concern is How can I write the variable names without python including them as part of the query text?
Aug 21 in Python by Arvind
• 2,960 points
20 views

1 answer to this question.

0 votes
cursor.execute("INSERT INTO table VALUES (%s, %s, %s)", (var1, var2, var3))

I think this should solve your query. Here the parameters are passed as a tuple.

answered Aug 21 by Neel
• 3,010 points

Related Questions In Python

0 votes
1 answer

Is it possible in Python requests to print entire HTTP request?

A better idea is to use the ...READ MORE

answered Nov 26, 2018 in Python by Nymeria
• 3,520 points
139 views
0 votes
3 answers
0 votes
1 answer

is it possible to do method overloading in python?

You cannot have two methods with the ...READ MORE

answered Mar 25 in Python by Mohammad
• 3,060 points
40 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 287 views
+4 votes
6 answers
0 votes
1 answer

Is it possible to print a string and a variable in a single print statement in Python?

This can be done using simple string ...READ MORE

answered Jul 15 in Python by Neel
• 3,010 points
29 views
0 votes
1 answer

Is it possible to run a function in Python using the command line?

Suppose your file name is demo.py and ...READ MORE

answered Jun 26 in Python by Neel
• 3,010 points
52 views