How to determine if NULL is contained in an array in Postgres?
select exists (
select 1
from unnest(array[1, null]) s(a)
where a is null
);
exists
--------
t
Or shorter:
select bool_or(a is null)
from unnest(array[1, null]) s(a)
;
bool_or
---------
t
One more construction, like @Clodoaldo Neto proposed. Just more compact expression:
CREATE TEMPORARY TABLE null_arrays (
id serial primary key
, array_data int[]
);
INSERT INTO null_arrays (array_data)
VALUES
(ARRAY[1,2, NULL, 4, 5])
, (ARRAY[1,2, 3, 4, 5])
, (ARRAY[NULL,2, 3, NULL, 5])
;
SELECT
*
FROM
null_arrays
WHERE
TRUE = ANY (SELECT unnest(array_data) IS NULL)
;