Postgres-与空时间戳比较

wut*_*aer 2 postgresql timestamp

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

在postgres 9中

this_.lastModified<=NULL
Run Code Online (Sandbox Code Playgroud)

评估为真,为什么?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)
Run Code Online (Sandbox Code Playgroud)

Igo*_*nko 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)
Run Code Online (Sandbox Code Playgroud)

如果这里所有比较:

d2_.hardwareID='muh' and this_.timestamp='2013-08-02 00:00:00' and m3_.id=0
Run Code Online (Sandbox Code Playgroud)

评估为“ true”,整个​​子句评估为true:

where u1_.userID='XXXX' and not (true and null)
Run Code Online (Sandbox Code Playgroud)

true and null 评估为 null

where u1_.userID='XXXX' and not null
Run Code Online (Sandbox Code Playgroud)

not null 评估为 null

where u1_.userID='XXXX' and null
Run Code Online (Sandbox Code Playgroud)

如果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)
Run Code Online (Sandbox Code Playgroud)

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