Executing “SELECT … WHERE … IN …” using MySQLdb

后端 未结 10 1994
耶瑟儿~
耶瑟儿~ 2020-11-29 21:23

I\'m having a problem executing some SQL from within Python, despite similar SQL working fine from the mysql command-line.

The table looks like this:

10条回答
  •  無奈伤痛
    2020-11-29 22:09

    Have been trying every variation on João's solution to get an IN List query to work with Tornado's mysql wrapper, and was still getting the accursed "TypeError: not enough arguments for format string" error. Turns out adding "*" to the list var "*args" did the trick.

    args=['A', 'C']
    sql='SELECT fooid FROM foo WHERE bar IN (%s)'
    in_p=', '.join(list(map(lambda x: '%s', args)))
    sql = sql % in_p
    db.query(sql, *args)
    

提交回复
热议问题