2

嗨,这不是一个真正的问题,我只是想了解原因:

在postgres 9中

this_.lastModified<=NULL

评估为真,为什么?lastModified 是没有时区的时间戳

我认为将其解释为“this_.lastModified<=0”会更合乎逻辑,如果 0 是最低日期并且 lastModified 是正常日期,则它应该评估为 false

完整的查询如下所示

select 
this_.*
from Entity this_ 
inner join DEntity d2_ on this_.device=d2_.id 
inner join u u1_ on this_.learner=u1_.userID 
inner join LMEntity m3_ on this_.method=m3_.id 
where u1_.userID='XXXX' and not (d2_.hardwareID='muh' and this_.timestamp='2013-08-02 00:00:00' and m3_.id=0 and this_.lastModified<=NULL)
4

1 回答 1

6

this_.lastModified<=NULL总是评估为null,在这种情况下,您的where子句有效:

where u1_.userID='XXXX' and not (d2_.hardwareID='muh' and this_.timestamp='2013-08-02 00:00:00' and m3_.id=0 and null)

如果这里的所有比较:

d2_.hardwareID='muh' and this_.timestamp='2013-08-02 00:00:00' and m3_.id=0

评估为“真”,整个子句评估为真:

where u1_.userID='XXXX' and not (true and null)

true and null评估为null

where u1_.userID='XXXX' and not null

not null评估为null

where u1_.userID='XXXX' and null

如果u1_.userID='XXXX'相等true, 则u1_.userID='XXXX' and null计算为null

并且where null等于where false

简而言之,整个

where u1_.userID='XXXX' and not (d2_.hardwareID='muh' and this_.timestamp='2013-08-02 00:00:00' and m3_.id=0 and this_.lastModified<=NULL)

将评估nullifu1_.userID='XXXX'和 all of d2_.hardwareID='muh' and this_.timestamp='2013-08-02 00:00:00' and m3_.id=0givetrue

于 2013-08-02T09:54:28.760 回答