python - Python 中的子句查询(pymysql 和 mysql.connector)

标签 python mysql sql pymysql

<分区>

我想使用这个查询:

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

我有 pymysql 和 mysql.connector for MySQL with Python。

这适用于 pymysql:

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

但它不适用于 mysql.connector。它给我这样的错误 'MySQLConverter' object has no attribute '_tuple_to_mysql'

pymysql 有一个很好的解决方案,但我无法在 mysql.connector 上实现。你能帮帮我吗?

最佳答案

怎么样

db = cur.execute('select x from y where z in (%s,%s,%s)',tuple(args))

关于python - Python 中的子句查询(pymysql 和 mysql.connector),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23973572/

相关文章:

python - PasteDeploy 与 uwsgi 一起使用时抛出 TypeError

php - 从表中选择列1、列2,其中值=某个值

php - 搜索查询,例如 Twitter 热门话题

mysql - 如何使用多个 View 创建临时表

java - ERROR : java. sql.SQLSyntaxErrorException:您的 SQL 语法有错误;

sql - SSMS 脚本选项

python - 如何删除重复的连续字符并使用正则表达式保留第一个字符?

python - 从语料库中删除非 ASCII

python - 从 pycuda.compiler 导入 SourceModule

php - 如何使用 RedBeanPHP 从表中获取 id 编号顺序有间隙的随机行?