如何确定Postgres中的数组中是否包含NULL?目前正在使用Postgres 9.3.3.

如果我使用以下选项进行测试,则返回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

我也try 过:

  1. @> (contains)
  2. <@(包含在中)
  3. &amp&(重叠)

推荐答案

select exists (
    select 1 
    from unnest(array[1, null]) s(a)
    where a is null
);
 exists 
--------
 t

或更短:

select bool_or(a is null)
from unnest(array[1, null]) s(a)
;
 bool_or 
---------
 t

Postgresql相关问答推荐

如何在Common Lisp中使用Postmodern在表更改时获得通知?

如何在生成的列的表达式中使用TIMESTAMP WITH时区列?

使用pg_repack从PostgreSQL中的表中删除OID

如何删除Devtainer之前创建的PostgreSQL数据库?

gitlab在ubuntu上安装duplicate schema问题

postgres hierarchy - 用祖先的值填充缺失值

使用正则表达式计算 SQL 查询中 WHERE 过滤器的数量

如何将 NULL 值插入 UUID 而不是零

在 PostgreSQL 中返回插入的行

Windows PSQL 命令行: is there a way to allow for passwordless login?

如何让 Rails 使用 SSL 连接到 PostgreSQL?

如何在可选参数上查询 postgres?

datagrip 无法应用更改 此表是只读的

SQL Select 一列中具有重复值的所有行

如何将主键添加到视图?

PGError:错误: column of relation does not exist

Windows 上的 GeoDjango:Could not find the GDAL library" / "OSError: [WinError 126] The specified module could not be found

使用 Hibernate 注释映射 PostgreSQL 串行类型

如何在 psql 中设置默认显示模式

Postgres DB 上的整数超出范围