3

I want to use this query:

select x from y where z in ("a", "b", "c")

I have pymysql and mysql.connector for MySQL with Python.

This works with pymysql:

args = ["a", "b", "c"]
db = cur.execute('select x from y where z in %s',(tuple(args),))

But it doesn't work with mysql.connector. It gives me error like 'MySQLConverter' object has no attribute '_tuple_to_mysql'.

pymysql has a great solution, but I couldn't realize that on mysql.connector. Can you help me please?

kadir_cakir
  • 1,013
  • 1
  • 16
  • 22
  • 1
    Also [SQLAlchemy WHERE IN single value (raw SQL)](http://stackoverflow.com/q/21481541). The answer to the question I linked you to uses `?` as the placeholder, simply use `%s` as the SQL parameter placeholder instead. The second link in this comment generates `:i0`, etc. named placeholders; more complex and probably not needed here. – Martijn Pieters May 31 '14 at 18:34

1 Answers1

1

how about

db = cur.execute('select x from y where z in (%s,%s,%s)',tuple(args))
Fabricator
  • 12,722
  • 2
  • 27
  • 40