我使用Postgres的這個查詢Postgres的NOT IN(空)沒有給出結果
select
*
from Entity this_
where
(this_.ID not in (null))
爲什麼這讓我沒有結果?我希望得到所有行的id是不是空
與
(this_.ID not in (1))
我得到預期的結果
我使用Postgres的這個查詢Postgres的NOT IN(空)沒有給出結果
select
*
from Entity this_
where
(this_.ID not in (null))
爲什麼這讓我沒有結果?我希望得到所有行的id是不是空
與
(this_.ID not in (1))
我得到預期的結果
的[not] in (null)
結果將始終爲NULL。爲了比較空,你需要is [not] null
或is [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)
PostgreSQL使用NULL作爲未定義的值。
你問的是返回不在列表中的項目或未定義的值。由於undefined意味着你不知道里面是什麼,PostgreSQL不會返回任何項目,因爲根本無法響應請求。
雖然請求:
select * from Entity where id in (1, null)
可以返回的記錄,因爲如果它發現與ID的元素= 1知道是集合中
請求:
select * from Entity where (ID not in (1, null))
不能滿足因爲空值可以是任何值。
意味着選擇像「select * from實體其中(ID不在(1,null))」是不可能的? – wutzebaer
@wutzebaer已更新 –