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搜索要简单得多,它与可能有害的模式源一起使用安全性会高一些。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值