我有一个奇怪的问题,在where子句中,我无法获得一个带有参数的SQL查询来处理字符串比较--我没有返回一行。当我通过bash连接到MySQL db时,查询可以工作。
工作(得到我的行):
select * from my_table where my_column = 'my_string';同样有效(得到我的行):
cursor.execute(
"""
select *
from my_table
where my_column = 'my_string'
"""
)不工作(cursor.fetchall()是[]):
cursor.execute(
"""
select *
from my_table
where my_column = '%s'
""",
('my_string')
)发布于 2019-07-16 09:00:27
要小心元组。我想你需要('my_string',)。
FYI我写了@tscherg在问题下面的评论中提到的原始评论。
发布于 2019-07-16 08:50:44
删除引号:
cursor.execute(
"""
select *
from my_table
where my_column = %s
""",
('my_string')
)https://stackoverflow.com/questions/57053384
复制相似问题