Skip to content

POSTGRESQL-判断数组有交集

判断一个数组中元素是否在另一个数组中出现,也就是数组取交集。

关键字 &&

sql
select array['ishypertension'] && array['ishypertension','isDiabetes'];   -- true
select array['xx'] && array['ishypertension','isDiabetes']; -- false
select array['ishypertension'] && array['ishypertension','isDiabetes'];   -- true
select array['xx'] && array['ishypertension','isDiabetes']; -- false
sql
select  
    menu_id, classify_code  
from phpg_nbphs.menu_classify where string_to_array( classify_code, ',' ) && 
       array['ishypertension','isDiabetes']
select  
    menu_id, classify_code  
from phpg_nbphs.menu_classify where string_to_array( classify_code, ',' ) && 
       array['ishypertension','isDiabetes']