2013-07-26 23 views

回答

16

[not] in (null)結果將始終爲NULL。爲了比較空,你需要is [not] nullis [not] distinct from null

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

如果你想where (ID not in (1,null))爲您的評論,你可以做

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

意味着選擇像「select * from實體其中(ID不在(1,null))」是不可能的? – wutzebaer

+1

@wutzebaer已更新 –

7

PostgreSQL使用NULL作爲未定義的值。
你問的是返回不在列表中的項目或未定義的值。由於undefined意味着你不知道里面是什麼,PostgreSQL不會返回任何項目,因爲根本無法響應請求。
雖然請求:

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

可以返回的記錄,因爲如果它發現與ID的元素= 1知道是集合中
請求:

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

不能滿足因爲空值可以是任何值。