您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“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結(jié)合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 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測試sdfasdf'); INSERT 0 1 Time: 1.423 ms [local]:5432 pg12@testdb=# insert into t_like(id,c1) values(3,'astestfe測試sdfasdf'); INSERT 0 1 Time: 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特性是什么”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進入相關(guān)頻道進行查詢,關(guān)注我們,繼續(xù)學習!
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。