Postgres NOT IN (null) gives no result

后端 未结 6 1336
长发绾君心
长发绾君心 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:31

    PostgreSQL uses NULL as undefined value.
    What you're asking is to return the items that are not in a list or an undefined value. Since undefined means that you do not know what's inside, PostgreSQL does not return any item because simply can not respond to the request.
    While the request:

    select * from Entity where id in (1, null)
    

    can return the records, because if it finds an element with ID = 1 knows that is in the collection
    the request:

    select * from Entity where (ID not in (1, null))
    

    can not be satisfied because the null value can be any value.

提交回复
热议问题