![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, I saw this behaviour in PostgreSQL 7.2. (Once again, I know this is an old release but I do not have a newer version installed, and I am only using the server for research purposes). If you execute the following statement SELECT (CAST('01.01.2004 10:01:00' AS TIMESTAMP) - CAST('01.01.2004 10:00:00' AS TIMESTAMP)) + CAST('01.01.2004 10:00:00' AS TIMESTAMP); The result returned is: ?column? --------------------- 2004-01-01 00:01:00 (1 row) I was expecting: 2004-01-01 10:01:00. Tried it on Oracle 8.0.5: SELECT TO_DATE('01.01.2004 10:01:00', 'DD.MM.YYYY HH:MI:SS') - TO_DATE('01.01.2004 10:00:00', 'DD.MM.YYYY HH:MI:SS') + TO_DATE('01.01.2004 10:00:00', 'DD.MM.YYYY HH:MI:SS') FROM DUAL; --------------------------- 2004-01-01 10:01:00 (1 row selected) And MSSQL 7: SELECT (CAST('01.01.2004 10:01:00' AS DATETIME) - CAST('01.01.2004 10:00:00' AS DATETIME) + CAST('01.01.2004 10:00:00' AS DATETIME)); --------------------------- 2004-01-01 10:01:00.000 (1 row(s) affected) Is this a bug? Same thing happens if I use TimestampTZ rather than Timestamp. Best regards, Ilir ____________________________________________ Ilir Gashi PhD Student Centre for Software Reliability City University Northampton Square, London EC1V 0HB email: i.gashi (AT) city (DOT) ac.uk website: http://www.csr.city.ac.uk/csr_city/staff/gashi/ ____________________________________________ ---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org |
#3
| |||
| |||
|
|
Hi, I saw this behaviour in PostgreSQL 7.2. (Once again, I know this is an old release but I do not have a newer version installed, and I am only using the server for research purposes). If you execute the following statement SELECT (CAST('01.01.2004 10:01:00' AS TIMESTAMP) - CAST('01.01.2004 10:00:00' AS TIMESTAMP)) + CAST('01.01.2004 10:00:00' AS TIMESTAMP); The result returned is: ?column? --------------------- 2004-01-01 00:01:00 (1 row) I was expecting: 2004-01-01 10:01:00. Tried it on Oracle 8.0.5: SELECT TO_DATE('01.01.2004 10:01:00', 'DD.MM.YYYY HH:MI:SS') - TO_DATE('01.01.2004 10:00:00', 'DD.MM.YYYY HH:MI:SS') + TO_DATE('01.01.2004 10:00:00', 'DD.MM.YYYY HH:MI:SS') FROM DUAL; --------------------------- 2004-01-01 10:01:00 (1 row selected) And MSSQL 7: SELECT (CAST('01.01.2004 10:01:00' AS DATETIME) - CAST('01.01.2004 10:00:00' AS DATETIME) + CAST('01.01.2004 10:00:00' AS DATETIME)); --------------------------- 2004-01-01 10:01:00.000 (1 row(s) affected) Is this a bug? Same thing happens if I use TimestampTZ rather than Timestamp. Best regards, Ilir ____________________________________________ Ilir Gashi PhD Student Centre for Software Reliability City University Northampton Square, London EC1V 0HB email: i.gashi (AT) city (DOT) ac.uk website: http://www.csr.city.ac.uk/csr_city/staff/gashi/ ____________________________________________ ---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org |
#4
| |||
| |||
|
|
SELECT '01.01.2004 10:00:00'::timestamp + ('01.01.2004 10:01:00'::timestamp - '01.01.2004 10:00:00'::timestamp)::interval; ?column? --------------------- 2004-01-01 10:01:00 (1 row) works fine in my 7.4.2 |
|
Interesting.... If I reverse the order it works... agencysacks=# SELECT CAST('01.01.2004 10:00:00' AS TIMESTAMP) + (CAST('01.01.2004 10:01:00' AS TIMESTAMP) - CAST('01.01.2004 10:00:00' AS TIMESTAMP)) as answer; answer --------------------- 2004-01-01 10:01:00 (1 row) |
|
However your original... agencysacks=# SELECT (CAST('01.01.2004 10:01:00' AS TIMESTAMP) - CAST('01.01.2004 10:00:00' AS TIMESTAMP)) + CAST('01.01.2004 10:00:00' AS TIMESTAMP); ERROR: operator does not exist: interval + timestamp without time zone HINT: No operator matches the given name and argument type(s). You may need to add explicit type casts. agencysacks=# select version(); version ------------------------------------------------------------------------------------------------------------------------- PostgreSQL 7.4.2 on powerpc-apple-darwin7.2.0, compiled by GCC gcc (GCC) 3.3 20030304 (Apple Computer, Inc. build 1495) (1 row) Looks like postgresql demands the order to be timestamp +- interval. Ted |
#5
| |||
| |||
|
|
I saw this behaviour in PostgreSQL 7.2. (Once again, I know this is an old release but I do not have a newer version installed, and I am only using the server for research purposes). If you execute the following statement SELECT (CAST('01.01.2004 10:01:00' AS TIMESTAMP) - CAST('01.01.2004 10:00:00' AS TIMESTAMP)) + CAST('01.01.2004 10:00:00' AS TIMESTAMP); |
#6
| |||
| |||
|
|
Ilir Gashi <I.Gashi (AT) city (DOT) ac.uk> writes: I saw this behaviour in PostgreSQL 7.2. (Once again, I know this is an old release but I do not have a newer version installed, and I am only using the server for research purposes). If you execute the following statement SELECT (CAST('01.01.2004 10:01:00' AS TIMESTAMP) - CAST('01.01.2004 10:00:00' AS TIMESTAMP)) + CAST('01.01.2004 10:00:00' AS TIMESTAMP); (There is a timestamp + interval operator, so you could make it work by flipping around the outer addition.) |
#7
| |||
| |||
|
|
On Fri, 2 Jul 2004, Tom Lane wrote: (There is a timestamp + interval operator, so you could make it work by flipping around the outer addition.) Should we be providing an interval + timestamp operator as well since it looks like the spec implies both orderings should work? |
#8
| |||
| |||
|
|
Stephan Szabo <sszabo (AT) megazone (DOT) bigpanda.com> writes: On Fri, 2 Jul 2004, Tom Lane wrote: (There is a timestamp + interval operator, so you could make it work by flipping around the outer addition.) Should we be providing an interval + timestamp operator as well since it looks like the spec implies both orderings should work? If you see spec support for it, then yes ... where do you read that exactly? |
#9
| |||
| |||
|
|
Should we be providing an interval + timestamp operator as well since it looks like the spec implies both orderings should work? If you see spec support for it, then yes ... where do you read that exactly? SQL92 (draft) 4.5.3 Operators involving datetimes and intervals (the table appears to be the same in SQL99 4.7.3) |
![]() |
| Thread Tools | |
| Display Modes | |
| |