9.7. Pattern Matching

9.7. Pattern Matching
9.7. 模式匹配
There are three separate approaches to pattern matching provided by PostgreSQL: the traditional SQL LIKE operator, the more recent SIMILAR TO operator (added in SQL:1999), and POSIX-style regular expressions. Aside from the basic “does this string match this pattern?” operators, functions are available to extract or replace matching substrings and to split a string at matching locations.
PostgreSQL提供了三種單獨的模式匹配方法:傳統的SQL LIKE運算符,SIMILAR TO運算符(在SQL:1999中添加)和POSIX樣式的正則表達式。除了基本的“此字符串是否匹配此模式?”運算符,函數可用於提取或替換匹配的子字符串並在匹配的位置拆分字符串。
 
Tip
小貼士
If you have pattern matching needs that go beyond this, consider writing a user-defined function in Perl or Tcl.
如果有超出此範圍的模式匹配需求,可以考慮使用Perl或Tcl編寫用戶自定義的函數。
 
Caution
注意
While most regular-expression searches can be executed very quickly, regular expressions can be contrived that take arbitrary amounts of time and memory to process. Be wary of accepting regular-expression search patterns from hostile sources. If you must do so, it is advisable to impose a statement timeout.
儘管大多數正則表達式搜索可以非常快速地執行,但卻也可以構造能夠耗費任意時間及內存去執行的正則表達式。 因此從未知來源接受正則表達式的時候,一定要謹慎。 如果必須這樣做,則建議強制限制語句超時。
 
Searches using SIMILAR TO patterns have the same security hazards, since SIMILAR TO provides many of the same capabilities as POSIX-style regular expressions.
使用SIMILAR TO模式進行的搜索具有相同的安全隱患,因爲SIMILAR TO提供了許多與POSIX樣式正則表達式相同的功能。
 
LIKE searches, being much simpler than the other two options, are safer to use with possibly-hostile pattern sources.
與其他兩個選項相比,LIKE搜索要簡單得多,它與可能有害的模式源一起使用安全性會高一些。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章