postgresql 數據庫中 like 、ilike、~~、~~*、~、~*的含義

like 匹配
ilike 不區分大小寫匹配
~~ 等價於 like
~~* 等價於 ilike
~ 匹配正則表達式,大小寫相關
~* 匹配正則表達式,大小寫無關

對應的 not 操作

not like 不匹配
not ilike 不區分大小不匹配
!~~ 等價於 not like
!~~* 等價於 not ilike
!~ 不匹配正則表達式,大小寫相關
!~* 不匹配正則表達式,大小寫無關

通配符

% 百分號用於匹配字符串序列,可匹配任意組合
_ 下劃線用於匹配任何單一字符

如果想要做前綴匹配或後綴匹配,可以用下面的方法

1、前綴模糊查詢。

select * from table where like 'ab%';
select * from table where ~~ 'ab%';
select * from table where ~ '^ab';

2、後綴模糊查詢。

select * from table where like '%ab';
select * from table where ~~ '%ab';
select * from table where ~ 'ab$';

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章