How to determine if NULL is contained in an array in Postgres?

前端 未结 5 1184
耶瑟儿~
耶瑟儿~ 2021-01-01 15:41

How do I determine if NULL is contained in an array in Postgres? Currently using Postgres 9.3.3.

If I test with the following select it returns contains_null =

5条回答
  •  不知归路
    2021-01-01 16:25

    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
    

提交回复
热议问题