dbTalk Databases Forums  

[BUGS] Time intervals in select statement

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] Time intervals in select statement in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Luke McFarlane
 
Posts: n/a

Default [BUGS] Time intervals in select statement - 10-19-2004 , 02:12 AM






Hello

Given the following example table:

CREATE TABLE foo ( create_time TIMESTAMP WITHOUT TIME ZONE );

INSERT INTO foo (create_time) VALUES (now());
INSERT INTO foo (create_time) VALUES (now());
INSERT INTO foo (create_time) VALUES (now());

This select statement works:

SELECT create_time, create_time + '8 days 16:49:22.600601' FROM foo;

create_time | ?column?
----------------------------+----------------------------
2004-10-19 16:59:31.065279 | 2004-10-28 09:48:53.66588
2004-10-19 16:59:33.790118 | 2004-10-28 09:48:56.390719
2004-10-19 16:59:34.398063 | 2004-10-28 09:48:56.998664

but this select statement doesnt:

SELECT create_time, create_time - '8 days 16:49:22.600601' FROM foo;

ERROR: invalid input syntax for type timestamp: "8 days 16:49:22.600601"

How can the expression '8 days 16:49:22.600601' be valid in the first
SELECT but not in the second?

I have reproduced this on 7.4.1 and 7.4.5.

Thanks
Luke





---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] Time intervals in select statement - 10-19-2004 , 02:28 AM






Luke McFarlane <luke (AT) fisheye (DOT) com.au> writes:
Quote:
SELECT create_time, create_time - '8 days 16:49:22.600601' FROM foo;

ERROR: invalid input syntax for type timestamp: "8 days 16:49:22.600601"
Cast the constant to interval explicitly.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org


Reply With Quote
  #3  
Old   
Luke McFarlane
 
Posts: n/a

Default Re: [BUGS] Time intervals in select statement - 10-19-2004 , 02:35 AM



Tom

Yes, that does indeed work.

It's interesting why addition assumes one operand is interval while
subtraction assumes it is timestamp? It should at least be consistent, IMHO.

Cheers
Luke

Tom Lane wrote:

Quote:
Luke McFarlane <luke (AT) fisheye (DOT) com.au> writes:


SELECT create_time, create_time - '8 days 16:49:22.600601' FROM foo;





ERROR: invalid input syntax for type timestamp: "8 days 16:49:22.600601"



Cast the constant to interval explicitly.

regards, tom lane



---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly


Reply With Quote
  #4  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] Time intervals in select statement - 10-19-2004 , 09:07 AM



Luke McFarlane <luke (AT) fisheye (DOT) com.au> writes:
Quote:
It's interesting why addition assumes one operand is interval while
subtraction assumes it is timestamp? It should at least be consistent, IMHO.
There is no timestamp + timestamp operator, for reasons that should be
fairly apparent. There are both timestamp - timestamp (yielding interval)
and timestamp - interval (yielding timestamp), and in case of ambiguity
the preferred interpretation is the one with the same datatype on both
sides. See
http://www.postgresql.org/docs/7.4/s...conv-oper.html

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.