PostgreSQL中的Putting multiple LIKE patterns into an array特性是什么
本篇内容主要讲解"PostgreSQL中的Putting multiple LIKE patterns into an array特性是什么",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"PostgreSQL中的Putting multiple LIKE patterns into an array特性是什么"吧!
LIKE用于模糊查询,如select from tablename where column like '%value%';如需要多个模糊匹配则需要使用多个like子句,如select from tablename where column like '%value1%' or column like '%value2%' or column like '%value3%'或者select * from tablename where column like '%value1%' and column like '%value2%' and column like '%value3%'。PG提供了ANY/ALL结合ARRAY来简化SQL:
select from tablename where column like '%value1%' or column like '%value2%' or column like '%value3%'
->
select from tablename where column like ANY(ARRAY['%value1%','%value2%','%value3%'])
select from tablename where column like '%value1%' and column like '%value2%' and column like '%value3%'
->
select from tablename where column like ALL(ARRAY['%value1%','%value2%','%value3%'])
测试脚本
[local]:5432 pg12@testdb=# create table t_like (id int,c1 varchar(20));CREATE TABLETime: 160.410 ms[local]:5432 pg12@testdb=# [local]:5432 pg12@testdb=# insert into t_like(id,c1) values(1,'asdfafetestsdfasdf');INSERT 0 1Time: 14.815 ms[local]:5432 pg12@testdb=# insert into t_like(id,c1) values(2,'asdfafe测试sdfasdf');INSERT 0 1Time: 1.423 ms[local]:5432 pg12@testdb=# insert into t_like(id,c1) values(3,'astestfe测试sdfasdf');INSERT 0 1Time: 1.486 ms[local]:5432 pg12@testdb=# select * from t_like where c1 like ANY(ARRAY['%test%','%测试%']); id | c1 ----+--------------------- 1 | asdfafetestsdfasdf 2 | asdfafe测试sdfasdf 3 | astestfe测试sdfasdf(3 rows)Time: 48.319 ms[local]:5432 pg12@testdb=# select * from t_like where c1 like ALL(ARRAY['%test%','%测试%']); id | c1 ----+--------------------- 3 | astestfe测试sdfasdf(1 row)Time: 2.463 ms[local]:5432 pg12@testdb=#
到此,相信大家对"PostgreSQL中的Putting multiple LIKE patterns into an array特性是什么"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
- 上一篇
【MOS】OCR/Vote disk 维护操作: (添加/删除/替换/移动) (文档 ID 1674859.1)
【MOS】OCR/Vote disk 维护操作: (添加/删除/替换/移动) (文档 ID 1674859.1)文档内容目标解决方案准备磁盘1. 磁盘大小2. 裸设备或者块设备 (pre 11.2)3
- 下一篇
Oracle 12C RAC安装grid时root.sh报错ORA-00845
Oracle 12C RAC安装grid时root.sh在二节点报错:CRS-2676: Start of 'ora.cssd' on 'prodb2' succeededCRS-2672: Atte