Postgres NOT IN (null) gives no result

后端 未结 6 1332
长发绾君心
长发绾君心 2021-02-07 05:03

I\'m using Postgres with this query

select 
*
from Entity this_ 
where 
(this_.ID not in (null))

Why does this give me no results? I would expe

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-07 05:11

    The result of [not] in (null) will always be null. To compare to null you need is [not] null or is [not] distinct from null

    select *
    from Entity this_ 
    where this_.ID is not null
    

    If you want where (ID not in (1,null)) as in your comment you can do

    where ID is not null and ID not in (1)
    

提交回复
热议问题