google-cloud-platform - 参数类型 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')
解决方案
在标准 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.name
和committer.name
,因为两者都将显示为name
。因此,我将它们更改为author_name
and committer_name
。
我还认为您实际上正在寻找的是替换为的结果repo_name
,repo_names_unnested
因此请尝试在 SELECT 子句中替换它。
推荐阅读
- php - 将 MongoDB 与 Symfony 5.2 连接时出错
- r - plotly::add_annotations() 无法处理因子变量(?)
- python - 沿着列表选择具有恒定距离的点,python
- html - 渐进式 Web 应用程序的 Apple 启动画面不显示
- weblogic - WebLogic 与 ActiveDirectory 的集成
- python - 使用 Openpyxl 加载工作簿时 Python 出错?
- nginx - nginx 静态文件与别名和子路径混淆
- c - 如何将char转换为int,反之亦然?
- c# - 如何在 Visual Studio 2019 中将清单文件添加到我的 C# 程序?
- reactjs - 如何在反应测试中的一个测试中处理两个不同的组件?