Using regex in WHERE in Postgres

后端 未结 2 1431
伪装坚强ぢ
伪装坚强ぢ 2020-12-14 05:05

I currently have the the following query:

select regexp_matches(name, \'foo\') from table;

How can I rewrite this so that the regex is in t

相关标签:
2条回答
  • 2020-12-14 05:58

    Just use match operator there:

    select * from table where name ~ 'foo';
    
    0 讨论(0)
  • 2020-12-14 06:00

    Write instead:

    select * from table where name ~ 'foo'
    

    The '~' operator produces a boolean result for whether the regex matches or not rather than extracting the matching subgroups.

    0 讨论(0)
提交回复
热议问题