2013-08-02 61 views
2

你好,這是不是一個真正的問題,我只是想知道爲什麼:Postgres的 - 比較空時間戳

在Postgres的9

this_.lastModified<=NULL 

值爲true,爲什麼呢?上次更改時間是無時區的時間戳

我認爲這將是更邏輯以解釋它像「this_.lastModified < = 0」,它的值應該爲假,如果0是最低的日期和上次更改時間是正常的日期

完整的查詢看起來像這樣

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) 
+2

不,它不是** ** 「評估爲真」。它評估爲「未知」。您將不得不向我們展示您正在使用的完整查詢,以便我們能夠理解爲什麼您認爲它的計算結果爲真。 –

+0

你爲什麼認爲它評估爲「真」?你能舉一個你認爲它的評估結果爲真的示例行嗎? –

回答

3

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:

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=0true

+0

感謝您的解釋 – wutzebaer