取消嵌套和重整大查询数组似乎会破坏null [英] Unnesting and reforming a big query array seems to destroy null

查看:22
本文介绍了取消嵌套和重整大查询数组似乎会破坏null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SELECT ARRAY(SELECT foo FROM UNNEST(CAST(NULL as ARRAY<STRING>)) as foo) is null 

返回假

vs.

SELECT CAST(NULL as ARRAY<STRING>) is null 

返回true

我的具体情况是我想使用

My specific situation is that I'd like to sort an array using

SELECT ARRAY(SELECT foo from UNNEST(bar) as foo Order by foo) as arr 

,如果数组最初为空,则将其保留为空.我愿意接受其他方法来对数组进行排序,但保留null(这意味着我不会挂断我的实现).

and keep the array as null if it was originally null. I'm open to alternatives for sorting the array but preserving null (meaning I'm not hung up on my implementation).

推荐答案

数组与具有数组类型的 NULL 不同.空数组是没有元素的数组.那就是您从 UNNEST()中获得的.因此,与 NULL 的比较是错误的.

An empty array is different from a NULL with an array type. An empty array is an array with no elements. That is what you get from the UNNEST(). So, the comparison to NULL is false.

第二个返回类型为数组的 NULL .这等效于 NULL ,因此比较是正确的.

The second is returning NULL typed as an array. This is equivalent to NULL, so the comparison is true.

这篇关于取消嵌套和重整大查询数组似乎会破坏null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆