存储过程:如何检查 postgresql 数组中是否存在 NULL?
Stored procedure: how to check if NULL is present in postgresql array or not?
数组 - user_zoned_ids
IF NULL = ANY(user_zones_ids) THEN
Do Something
END IF;
但是 IF 条件总是给出 false,即使数组中存在 NULL
您不能使用 ANY
运算符来检查 NULL 值。您必须取消嵌套数组并计算 NULL 元素的数量:
if (select count(*) from unnest(user_zones_ids) as t(x) where x is null) > 0 then
... do something ...
end if;
数组 - user_zoned_ids
IF NULL = ANY(user_zones_ids) THEN
Do Something
END IF;
但是 IF 条件总是给出 false,即使数组中存在 NULL
您不能使用 ANY
运算符来检查 NULL 值。您必须取消嵌套数组并计算 NULL 元素的数量:
if (select count(*) from unnest(user_zones_ids) as t(x) where x is null) > 0 then
... do something ...
end if;