0

Using MySQLDB, I am able to do database operations. But, I got stuck at one point where I need to construct a query having a where objectid in (variable no. of args) condition.
Since args are variable, I am unable to construct a query having matching number of %s.
Normally, I do this for a query like below:

select * from table where objectid in (args1, args2, args3, args4)

For query above, I would go like this and pass the relevant tuple having 4 members:

select * from table where objectid in (%s, %s, %s, %s) 

But, for a query like below, how do I match the number of %s for variable number of args:

select * from table where objectid in (args1, args2, args3, args4...)

Only thing I could think of doing is to create a tuple having as many number of %s as the args, in a for loop and then add it using string concatenation. Would this method be a wrong choice?

Mr.President
  • 163
  • 1
  • 9
  • 1
    I believe that is accomplished [like this](https://stackoverflow.com/questions/589284/imploding-a-list-for-use-in-a-python-mysqldb-in-clause), Mr.President. – JNevill Nov 12 '19 at 15:55
  • 1
    @JNevill Mission accomplished, thanks for your services! – Mr.President Nov 12 '19 at 16:00

0 Answers0