I have table t with an array column z in Postgres 9.5. I want to select id where z is either NULL OR {NULL}.
id | z
---+--------
1 | {NULL}
2 | null
See DBFIDDLE
I tried changing {NULL} to NULL with array_remove():
SELECT id,
array_remove(z,NULL) as removed
from t;
Returns:
id | z | removed
---+--------+-------
1 | {NULL} | {}
2 | null | null
However, if I query this:
select id, z from t where removed is null;
I still get id 1. Ideally, I'd like to avoid unnesting and grouping back up.
nullif(z, '{null}'){NULL}given your table definition.