【发布时间】:2014-05-06 20:43:04
【问题描述】:
如何确定 NULL 是否包含在 Postgres 中的数组中?目前使用 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
我也试过:
- @>(包含)
- &&(重叠)
【问题讨论】:
-
这个类似问题下的更多解决方案:stackoverflow.com/questions/34848009/…
-
create table scientist (id integer, firstname varchar(100), lastname varchar(100)); insert into scientist (id, firstname, lastname) values (1, 'albert', 'einstein'); insert into scientist (id, firstname, lastname) values (2, 'isaac', 'newton'); insert into scientist (id, firstname, lastname) values (3, 'marie', null); select * from scientist where lastname is null or lastname in ('einstein', 'newton', null);。我试过这个,但是选择查询没有在这里返回null条目。所以,我认为,这就是它的工作原理,数组中的null将不起作用。
标签: sql arrays postgresql