【发布时间】:2018-03-14 06:20:27
【问题描述】:
我想执行下面的查询,
select * from table where name LIKE %sachin%;
我是这样创建sql查询的,
sql = "select * from table where %s like '\%%s\%'"
它给了我以下错误,
ValueError: unsupported format character ''' (0x27) at index 42
我想要字符串前后的 '%' 符号。 我怎样才能做到这一点?它还应该减轻 SQL 注入。
【问题讨论】:
-
试试 POSIX 正则表达式。您可以在这里查看主题postgresql.org/docs/9.0/static/functions-matching.html
标签: python sql postgresql sql-injection