带有参数和通配符运算符的pandas read_sql [英] pandas read_sql with parameters and wildcard operator
本文介绍了带有参数和通配符运算符的pandas read_sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用以下代码通过python从sql检索数据:
I am trying to retrieve data from sql through python with the code:
query = ("SELECT stuff FROM TABLE WHERE name like %%(this_name)s%")
result = pd.read_sql(query,con=cnx,params={'this_name':some_name})
当我不必传递通配符%时,上面的代码可以完美地工作. 但是,在这种情况下,代码不起作用.如何在查询中传递通配符运算符?谢谢.
The code above works perfectly when I don't have to pass the wildcard operator %. However, in this case the code doesn't work. How can I pass in the query the wildcard operator? Thank you.
推荐答案
考虑将通配符运算符%
串联为传入值:
Consider concatenating the wildcard operator, %
, to passed in value:
query = ("SELECT stuff FROM TABLE WHERE name LIKE %(this_name)s")
result = pd.read_sql(query,con=cnx, params={'this_name': '%'+ some_name +'%'})
这篇关于带有参数和通配符运算符的pandas read_sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文