Regex and textmatching issue

▼魔方 西西 提交于 2019-12-12 04:54:30

问题


I am doing some basic text matching in Postgres 9.3.5.0.
Here is my code so far:

  Select text from eightks
  WHERE other_events = true and 
  keywordRegexs = [\y(director and member \s+  and resigned)\y/ix];

I am getting the following errors

psql:test3.sql:3: invalid command \y(director
psql:test3.sql:5: ERROR:  syntax error at or near "["
LINE 3:  keywordRegexs = [

I am trying to find documents which contain those exact phrases.


回答1:


The regular expression match operator in Postgres is ~.
The case insensitive variant is ~*.
Branches are enclosed in ().

SELECT text
FROM   eightks
WHERE  other_events = true
AND    keywordregexs ~* '(\y(director | member \s+ |resigned)\y)';

The meaning of "those exact phrases" is not clear in the question.
Details in the manual.



来源:https://stackoverflow.com/questions/25779596/regex-and-textmatching-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!