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, 2019 in Python by Arvind
• 3,050 points
9,238 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, 2019 by Neel
• 3,020 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,560 points
22,770 views
0 votes
1 answer
0 votes
4 answers

What is a Tuple in Python and how to use it?

Tuples  are a  Unchanging sequence of values, ...READ MORE

answered Jun 21, 2020 in Python by sahil
• 500 points
1,948 views
0 votes
1 answer

is it possible to do method overloading in python?

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

answered Mar 26, 2019 in Python by Mohammad
• 3,230 points
736 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,422 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,042 views
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, 2019 in Python by Neel
• 3,020 points
821 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, 2019 in Python by Neel
• 3,020 points
1,040 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP