[英]Matching special characters
我想匹配一個特殊字符列表( '-&
)的PostgreSQL查詢。 通過在線正則表達式編輯器,我進入了[\\'\\-\\&\\\\]
。 但是當我在查詢中使用它時,出現語法錯誤:
connection.execute("SELECT index, name FROM test21 WHERE test21.name ~ '[\'''\-\&\\]'")
結果ins
ProgrammingError: (ProgrammingError) syntax error at or near "\"
LINE 1: test21 WHERE test21.name ~ '['''\-\&\]'
^
我找到了其他答案,例如https://stackoverflow.com/a/25925429/380038 ,但這些都匹配所有特殊字符。
with q(str) as (
values ('abc'), ('a-b'), ('a''b'), ('a&b'), ('a\b'))
select str, str ~ '[''\-&\\]' bool
from q;
str | bool
-----+------
abc | f
a-b | t
a'b | t
a&b | t
a\b | t
(5 rows)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.