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?