You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 08:35:23