首页 > 解决方案 > 参数类型 ARRAY 的运算符 IN 没有匹配的签名

问题描述

我想使用“WHERE xxx IN ('aaa','bbb')”执行以下标准 SQL。

但是发生了错误。是否可以在标准 SQL 中使用“IN”?

标准 SQL

SELECT commit, author.name, committer.name, committer.time_sec,
committer.tz_offset, committer.date.seconds , subject, message,
repo_name
FROM `bigquery-public-data.github_repos.commits`
WHERE repo_name IN 
('tensorflow/tensorflow', 'facebook/react')

错误

No matching signature for operator IN for argument types ARRAY<STRING> and {STRING} at [5:17]

以下 Legacy SQL 似乎可以执行。

旧版 SQL

SELECT commit, author.name, committer.name, committer.time_sec,
committer.tz_offset, committer.date.seconds , subject, message,
repo_name
FROM [bigquery-public-data:github_repos.commits] 
WHERE repo_name IN 
('tensorflow/tensorflow', 'facebook/react')

标签: google-cloud-platformgoogle-bigquery

解决方案


在标准 SQL 中你不能真正做到这一点。但是在这篇文章How to use the UNNEST function in BigQuery to analyze event parameters in Analytics 中,他们很好地解释了这一点。

我认为这就是您获得所需结果的方式:

SELECT commit, author.name as author_name, committer.name as committer_name, committer.time_sec,
committer.tz_offset, committer.date.seconds , subject, message,
repo_name
FROM `bigquery-public-data.github_repos.commits`
CROSS JOIN UNNEST(repo_name) as repo_names_unnested
WHERE repo_names_unnested IN ('tensorflow/tensorflow', 'facebook/react')

请注意,您不能同时拥有author.namecommitter.name,因为两者都将显示为name。因此,我将它们更改为author_nameand committer_name

我还认为您实际上正在寻找的是替换为的结果repo_namerepo_names_unnested因此请尝试在 SELECT 子句中替换它。


推荐阅读