如何确定是否NULL被包含在Postgres的一个数组? [英] How to determine if NULL is contained in an array in Postgres?
本文介绍了如何确定是否NULL被包含在Postgres的一个数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何确定是否NULL被包含在Postgres的一个数组?目前使用的Postgres 9.3.3。
如果我在下面的测试中选择返回 contains_null = FALSE
。
选择Array [NULL,1,2,3,4,NULL] :: INT [] @> ARRAY [NULL] :: INT [] AS contains_null
选择Array [NULL,1,2,3,4,NULL] :: INT [] @> NULL作为contains_null
我也试过用:
- @>(含)
- < @(由包含)
- &放大器;&安培; (重叠)
解决方案
选择存在(
选择1
从UNNEST(数组[1,空])S(一)
其中a是空
);
存在
--------
ŧ
How do I determine if NULL is contained in an array in Postgres? Currently using Postgres 9.3.3.
If I test with the following select it returns contains_null = false
.
select ARRAY[NULL,1,2,3,4,NULL]::int[] @> ARRAY[NULL]::int[] AS contains_null
select ARRAY[NULL,1,2,3,4,NULL]::int[] @> NULL AS contains_null
I've also tried with:
- @> (contains)
- <@ (is contained by)
- && (overlap)
解决方案
select exists (
select 1
from unnest(array[1, null]) s(a)
where a is null
);
exists
--------
t
这篇关于如何确定是否NULL被包含在Postgres的一个数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文