0

I am interested in knowing if I can pass the name of the column in the select statement of MySQL as a parametrized query in python, like

<database_cursor>.execute("select %s from employee_name",("Name",))

I have tried executing the above in python IDLE, but it raised an error. I am assuming that the error is with the double/single quotations of the parametrized query i.e., the "Name" literal

in sql shell, the command works in the way like:

select Name from employee_name

I am assuming python is passing the statement in this format to sql

select "Name" from employee_name

My analysis is that the double quotes of "Name" is causing the issue. Is there any way to fix this problem and get the desired output from python-MySQL

  • 2
    Does this answer your question? [Python mysql using variable to select a certain field](https://stackoverflow.com/questions/31751380/python-mysql-using-variable-to-select-a-certain-field) – Yevgeniy Kosmak Jan 06 '22 at 18:38
  • Use SQL parameters only where you would use a literal value, not an identifier. – Bill Karwin Jan 06 '22 at 18:45

0 Answers0