如何在BigQuery中使用LIKE ANY?求可行替代方案
BigQuery中LIKE ANY操作符的替代方案
BigQuery不支持LIKE ANY操作符,要实现基于子字符串数组排除数据行,可以用以下两种可行方案:
方案一:使用EXISTS + UNNEST
通过UNNEST将数组拆分为单行记录,结合EXISTS判断是否存在匹配的子字符串,再通过not实现排除逻辑:
declare unlaunched_clistings array<string>; set unlaunched_clistings = {unlaunched_clistings} ; select * from {p}.simeon_logs.process_errors e where not exists ( select 1 from unnest(unlaunched_clistings) pattern where e.message like pattern )
方案二:使用REGEXP_CONTAINS + ARRAY_TO_STRING
将数组中的子字符串合并为正则表达式,用REGEXP_CONTAINS匹配。如果子字符串包含正则特殊字符(如.、*),记得先用REGEXP_ESCAPE转义:
declare unlaunched_clistings array<string>; set unlaunched_clistings = {unlaunched_clistings} ; -- 转义正则特殊字符并合并为正则表达式 declare regex_pattern string; set regex_pattern = array_to_string( array(select regexp_escape(pattern) from unnest(unlaunched_clistings) pattern), '|' ); select * from {p}.simeon_logs.process_errors e where not regexp_contains(e.message, regex_pattern)
内容的提问来源于stack exchange,提问作者delo4d
相关产品推荐
相关产品推荐

