1

I am trying to do something like this

cur.execute('''SELECT ID FROM ? WHERE Name = ?''', (var1,var2) )

but got a error message of syntax error near "?"

I have also tried

 cur.execute("SELECT ID FROM" + var1 + "WHERE Name = ?", (var2,))

same error happened

1 Answer 1

1

You can't use placeholder for names of columns or tables.

The second example fails because of missing spaces. Correct to:

cur.execute("SELECT ID FROM " + var1 + " WHERE Name = ?", (var2,))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.