本篇內(nèi)容主要講解“PostgreSQL中的Putting multiple LIKE patterns into an array特性是什么”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“PostgreSQL中的Putting multiple LIKE patterns into an array特性是什么”吧!
曲阜網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)!從網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、響應(yīng)式網(wǎng)站等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營(yíng)維護(hù)。創(chuàng)新互聯(lián)于2013年創(chuàng)立到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來(lái)保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)。
LIKE用于模糊查詢,如select from tablename where column like ‘%value%’;如需要多個(gè)模糊匹配則需要使用多個(gè)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結(jié)合ARRAY來(lái)簡(jiǎn)化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%’])
測(cè)試腳本
[local]:5432 pg12@testdb=# create table t_like (id int,c1 varchar(20)); CREATE TABLE Time: 160.410 ms [local]:5432 pg12@testdb=# [local]:5432 pg12@testdb=# insert into t_like(id,c1) values(1,'asdfafetestsdfasdf'); INSERT 0 1 Time: 14.815 ms [local]:5432 pg12@testdb=# insert into t_like(id,c1) values(2,'asdfafe測(cè)試sdfasdf'); INSERT 0 1 Time: 1.423 ms [local]:5432 pg12@testdb=# insert into t_like(id,c1) values(3,'astestfe測(cè)試sdfasdf'); INSERT 0 1 Time: 1.486 ms [local]:5432 pg12@testdb=# select * from t_like where c1 like ANY(ARRAY['%test%','%測(cè)試%']); id | c1 ----+--------------------- 1 | asdfafetestsdfasdf 2 | asdfafe測(cè)試sdfasdf 3 | astestfe測(cè)試sdfasdf (3 rows) Time: 48.319 ms [local]:5432 pg12@testdb=# select * from t_like where c1 like ALL(ARRAY['%test%','%測(cè)試%']); id | c1 ----+--------------------- 3 | astestfe測(cè)試sdfasdf (1 row) Time: 2.463 ms [local]:5432 pg12@testdb=#
到此,相信大家對(duì)“PostgreSQL中的Putting multiple LIKE patterns into an array特性是什么”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!