Postgresql包含where子句

Gop*_*h.R 9 sql postgresql select contains where-clause

postgres中有功能contains吗?可用于where clause检查,传递的字符串是否包含在列中?

NPE*_*NPE 17

你可以用position()它.如果未找到子字符串,则返回零:

position(col2 in col1) <> 0
Run Code Online (Sandbox Code Playgroud)


Chr*_*ers 7

有很多方法可以解决这个问题:

  1. 使用like,, ilike和/或SIMILAR TO与||一起使用.要处理列,例如:

    WHERE col1 ilike '%' || col2 || '%';
    
    Run Code Online (Sandbox Code Playgroud)
  2. 使用位置作为NPE的答案

  3. 你也可以使用,regexp_matches但这更复杂.

  • 对于这种情况,也可以使用`col1~'abc'`或`col1~col2`. (4认同)