Postgres NOT IN (null) gives no result

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

    I had similar problem. My ego that I knew SQL well, got punctured. Here is the simplified example from scott/tiger tables.

    select empno, ename from emp where deptno not in (10, 20, null);
    

    Returned nothing. Although I use NOT IN condition very sparingly because it does not use index and is very slow. I prefer to use OUTER JOIN instead.

    I tried this query in Postgres and Oracle both and results are the same. So, must be a standards compliant result. NULL behaves this way only in NOT IN condition.

提交回复
热议问题