25

このクエリでPostgresを使用しています

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

これで結果が得られないのはなぜですか? IDがnullでないすべての行を取得することを期待します

(this_.ID not in (1))

私は期待される結果を得る

4

7 に答える 7

30

の結果[not] in (null)は常に 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)
于 2013-07-26T09:36:47.003 に答える