correct parameter usage for "select * where id in ..."

paul paul at subsignal.org
Sat Oct 28 06:44:39 EDT 2006


Frank Millman schrieb:
> If you want it to handle a variable number of values, you will have to
> programmatically construct the sql statement with the appropriate
> number of parameters.
>>> vals = (1,2,3,4,5)
>>> sql = "select * from table where value in ("+','.join("?"*len(vals))+")"
>>> print sql
'select * from table where value in (?,?,?,?,?)'

cheers
 Paul




More information about the Python-list mailing list