I use this:
create or replace function regexp_match_array(a text[], regexp text) returns boolean strict immutable language sql as $_$ select exists (select * from unnest(a) as x where x ~ regexp); $_$; comment on function regexp_match_array(text[], text) is 'returns TRUE if any element of a matches regexp'; create operator ~ ( procedure=regexp_match_array, leftarg=text[], rightarg=text ); comment on operator ~(text[], text) is 'returns TRUE if any element of ARRAY (left) matches REGEXP (right); think ANY(ARRAY) ~ REGEXP';
Then use it the same way you used ~ with text scalars:
=> select distinct gl from x where gl ~ 'SH' and array_length(gl,1) < 7; ββββββββββββββββββββββββββββββββββββββββ β gl β ββββββββββββββββββββββββββββββββββββββββ€ β {MSH6} β β {EPCAM,MLH1,MSH2,MSH6,PMS2} β β {SH3TC2} β β {SHOC2} β β {BRAF,KRAS,MAP2K1,MAP2K2,SHOC2,SOS1} β β {MSH2} β ββββββββββββββββββββββββββββββββββββββββ (6 rows)
Reece
source share