use*_*713 20 python mysql sqlalchemy
我的查询是:
result = connection.execute(
"select id_number from Table where string like '_stringStart%' limit 1;")
Run Code Online (Sandbox Code Playgroud)
给出错误:
query = query % escaped_args
TypeError: not enough arguments for format string
Run Code Online (Sandbox Code Playgroud)
一个快速的谷歌说使用%%而不是%,但这也不起作用.如何转义%或是否有另一种方法来查询以随机字母开头然后是某个序列的字符串?
zzz*_*eek 33
因为这是一个文字字符串,所以最好在这里使用绑定参数(如图所示text()):
from sqlalchemy import text
connection.execute(
text("select * from table where "
"string like :string limit 1"),
string="_stringStart%")
Run Code Online (Sandbox Code Playgroud)