Postgres - 与null-timestamp相比

时间:2013-08-02 09:21:47

标签: postgresql timestamp

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

在postgres 9

this_.lastModified<=NULL

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

我认为将其解释为“this_.lastModified&lt; = 0”更合乎逻辑,如果0是最低日期且lastModified是正常日期,则应该评估为假

完整查询如下所示

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)

1 个答案:

答案 0 :(得分:5)

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

评估为'true',整个子句的计算结果为true:

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'等于trueu1_.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)

将评估为null,如果u1_.userID='XXXX'且所有d2_.hardwareID='muh' and this_.timestamp='2013-08-02 00:00:00' and m3_.id=0给出true