pg-项目中用到的函数

排列顺序按照使用到的顺序,无优先级,仅作记录

1、regexp_split_to_table

SELECT * from regexp_split_to_table('111,222,333,444',',')

这个函数会生成一张临时表,很适合替代大数据量下的in查询优化,直通另一篇:in查询优化

持续更新-----------------------------》》》》》》》

2、数组类型的查询

components是一个数组类型varchar[],需要做范围查询,下面的写法都是左边包含右边

select * from t_rule where components @> '{a,b,c}' and '{a,b,c}' @>components   ---正好包含a,b,c

select * from t_rule where components @> '{a,b}'            --至少包含a,b

select * from t_rule where components @> '{a}' or components @> '{b}' or components @> '{c}'    --包含a,b,c中至少一个

select * from t_rule where '{a,b,c}' @> components       --限于a,b,c三个值范围内

 

posted @ 2021-03-26 11:48  鼠标的博客  阅读(248)  评论(0编辑  收藏  举报