tearf001
7/25/2018 - 1:50 AM

数组为空判断

SELECT arr,
       1 = all(arr) as allone,
       2 = all(arr) as alltwo,
       -- null is all(arr) as allnulls,
       1 = ALL(arr) IS NULL AND 2 = ALL(arr) IS NULL AS chk_simpl,
       TRUE = ALL (SELECT unnest(arr) IS NULL) AS chk_michael,
       (SELECT bool_and(e IS NULL) FROM unnest(arr) e) AS chk_bool_and,
       NOT EXISTS (SELECT unnest(arr) EXCEPT SELECT null) AS chk_exist
  FROM (VALUES('{1,2,NULL,3}' ::int []), ('{1,1,1}'), ('{2,2,2}'),
        ('{NULL,NULL,NULL}' ::int [])) t1(arr);