Postgres - compare to a null-timestamp

wutzebaer

hi this is not really a problem i just want to understand why:

in postgres 9

this_.lastModified<=NULL

evaluates to true, why? lastModified is a timestamp without timezone

i think it would be more logic to interpret it like "this_.lastModified<=0" which should evaluate to false if 0 is the lowest date and lastModified is a normal date

the complete query looks like this

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)
Igor Romanchenko

this_.lastModified<=NULL always evaluates to null and in this case your where clause is effectively:

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

if all of the comparisons here:

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

evaluates to 'true' the this whole clause evaluates to true:

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

true and null evaluates to null

where u1_.userID='XXXX' and not null

not null evaluates to null

where u1_.userID='XXXX' and null

if u1_.userID='XXXX' equal true, u1_.userID='XXXX' and null evaluates to null

and where null is equal to where false.

In short, the whole

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)

will evaluate to null if u1_.userID='XXXX' and all of d2_.hardwareID='muh' and this_.timestamp='2013-08-02 00:00:00' and m3_.id=0 gives true

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Postgres where clause compare timestamp

From Dev

Postgres compare timestamp with long unix timestamp

From Dev

Postgres copy null into timestamp column

From Dev

Postgres copy null into timestamp column

From Dev

How to tell if timestamp from Postgres in Java is null

From Dev

Postgres look for rows with same value and compare the timestamp, then update the old rows

From Dev

How to extract the year of timestamp field in "where" zone and compare with the current year using postgres 9.6?

From Dev

Compare Timestamp with another Timestamp object

From Dev

Conversion of oracle timestamp to postgres timestamp?

From Dev

Compare date + time with timestamp

From Dev

Compare two timestamp days

From Dev

Rails - ActiveRecord: Compare Timestamp

From Dev

Compare logs without timestamp

From Dev

cassandra: compare timestamp in python

From Java

Convert Hexadecimals to timestamp in postgres

From Dev

Postgres timestamp with timezone

From Dev

Converting a timestamp in milliseconds in Postgres

From Dev

Postgres timestamp to date

From Dev

Writing timestamp to Postgres with Pyspark

From Dev

Compare PHP current timestamp to timestamp in the database

From Dev

How to compare mysql timestamp with jquery timestamp?

From Java

Compare arrays in postgres

From Dev

Compare software version in postgres

From Dev

Compare software version in postgres

From Dev

How to compare Timestamp in where clause

From Dev

Compare property that can be a timestamp or FALSE

From Dev

Date Compare in HQL without timestamp

From Dev

MySQL & SqLite - compatibile timestamp compare

From Dev

Sql compare TimeStamp with normal date

Related Related

HotTag

Archive