0
votes

I have the following table with 4 rows only: enter image description here

When i run the query

 select * from TABLE9 
     where dateLastChanged < dateLastUploaded

on this table, i expect to see the rows 1 & 4, however i get this: enter image description here

When i run

 select * from TABLE9 
     where dateLastChanged > dateLastUploaded

i get enter image description here

, and to

 select * from TABLE9 
     where dateLastChanged <> dateLastUploaded

i get all 4 of it. ... where dateLastChanged = dateLastUploaded gets none.

I tried casting to timestamp-- got the same results:

 select * from TABLE9 
     where timestamp(dateLastChanged) < timestamp(dateLastUploaded)

Whats missing???

my first time with DB2 on a prj. increasingly "loving" it.

Note: I'm aware that i can get around this on the Java side.

//--------------------------

EDIT:

clarifying what i thought was clear in the Q:

How come

 select * from TABLE9 
     where dateLastChanged < dateLastUploaded

is returning dateLastChanged < dateLastUploaded, dateLastChanged > dateLastUploaded and dateLastChanged = dateLastUploaded.

How does DB2 decide which timestamp is greater, smaller, equal, not equal to one another. the timestamps for row tNumber=bbbbb were created and written at the same time.

//--------------------

EDIT-2

In my original Q - "greater-than/less-than" in the comparison of the timestamps is confused. This (the latter timestamp is greater/not) is easy enough to figure once i get passed the inconsistency i laid out in the Q and the edit right before this.

1
Care to explain why you think that '17:24' is less (that is, earlier) than '17:14'? - mustaccio
Have you ever looked at your timestamps? Just look close enough and you will find all your answers. Everythings works like expected! - MichaelTiefenbacher
I am also LOVING DB2 because it is correct. - data_henrik
@MichaelTiefenbacher well- hope not "Everythings works like expected!". Read the edit. - user6401178
Sorry your edit is confusing in my eyes. If you refer to your first example and tNumber=ccccc the 2016-08-13 is greater than 2016-08-03 - just looking at the date is enough. - MichaelTiefenbacher

1 Answers

1
votes

DB2 uses ISO-defined logic to compare timestamps. It means that for "lower" the earlier date/time is taken, for "greater" the later date/time. For your example DB2 has evaluated everything correctly. To get different results you need to change the values... :)