如何从ARRAY中排除NULL,以便查询不会失败 [英] How to exclude NULLs from ARRAY so query won't fail
本文介绍了如何从ARRAY中排除NULL,以便查询不会失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ARRAY_AGG 聚合函数包括它构建的数组中的NULLs
.当此类数组成为查询结果的一部分时,查询将失败,并显示以下错误:
ARRAY_AGG aggregate function includes NULLs
in the arrays it builds. When such arrays are part of query result, query fails with error:
数组不能有null元素;写作领域中的错误
Array cannot have a null element; error in writing field
即以下查询对此进行了演示:
i.e. the following query demonstrates it:
#standardSQL
SELECT ARRAY_AGG(x) FROM UNNEST([1,NULL,2,3]) x
我们如何解决呢?
推荐答案
您问的很高兴! BigQuery在某些聚合函数(包括ARRAY_AGG
)中支持IGNORE NULLS
和RESPECT NULLS
修饰符,因此您的查询变为
Glad you asked! BigQuery supports IGNORE NULLS
and RESPECT NULLS
modifiers in some of the aggregate functions, including ARRAY_AGG
, so your query becomes
#standardSQL
SELECT ARRAY_AGG(x IGNORE NULLS) FROM UNNEST([1,NULL,2,3]) x
and it passes producing [1,2,3]
. More details are in the documentation.
这篇关于如何从ARRAY中排除NULL,以便查询不会失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文