Python list of ints in prepared sql statement -


my question same python list of string sql in parameter have list of integers. python code use is:

ids = [1000032, 1000048] sql = 'select compno, compname, comptype component deptid in (?)'     cursor.execute(sql, [','.join(ids)]) 

and sybase database engine responds with:

pyodbc.error: ('07006', "[07006] [sybase][odbc driver][sql anywhere]cannot convert '1000032','1000048' numeric (-157) (sqlexecdirectw)") 

what correct way this?

imo more readable way build dynamic query string placeholders using str.format

ids = [1000032, 1000048] sql = 'select compno, compname, comptype component deptid in ({0})'  sql = sql.format(','.join('?' * len(ids))) cursor.execute(sql, (ids,)) ... 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -