If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Informix > Weird behavior with casts to datetime in where clause

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-07-09, 07:44
eiseli eiseli is offline
Registered User
 
Join Date: Oct 2009
Posts: 1
Question Weird behavior with casts to datetime in where clause

Hello all,

Probably, I've misunderstood something but I can't explain this behavior. While the following SQL statement works (and returns 4 rows):
Code:
SELECT * FROM pr_sqlstats WHERE when = '10:24'::datetime HOUR TO MINUTE;
the following returns an empty result (while I would expect at least 4 but normally more):
Code:
SELECT * FROM pr_sqlstats WHERE when = '10'::datetime HOUR TO HOUR;
This code is being executed on a table which has been created as follows:
Code:
  CREATE TABLE pr_sqlstats (
    when DATETIME YEAR TO MINUTE DEFAULT CURRENT YEAR TO MINUTE,
    who CHAR(8) DEFAULT USER,
    grp SMALLINT,
    id SMALLINT
  );
Thanks for anybody who can point me to the right direction.
Reply With Quote
  #2 (permalink)  
Old 10-09-09, 19:08
bigcalm bigcalm is offline
Registered User
 
Join Date: Jul 2009
Posts: 37
... WHERE when = '10'::datetime HOUR TO HOUR; ...

What this is actually doing is casting "10" to 10:00 effectively.

What you actually want is something of the order of...

where hour(when) = 10
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On