From: Thomas G. Lockhart Date: Sun, 21 Apr 2002 19:52:18 +0000 (+0000) Subject: Support alternate storage scheme of 64-bit integer for date/time types. X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=68b5c487affc563c9145ee23072c0626e5c423a0;p=users%2Fbernd%2Fpostgres.git Support alternate storage scheme of 64-bit integer for date/time types. Use "--enable-integer-datetimes" in configuration to use this rather than the original float8 storage. I would recommend the integer-based storage for any platform on which it is available. We perhaps should make this the default for the production release. Change timezone(timestamptz) results to return timestamp rather than a character string. Formerly, we didn't have a way to represent timestamps with an explicit time zone other than freezing the info into a string. Now, we can reasonably omit the explicit time zone from the result and return a timestamp with values appropriate for the specified time zone. Much cleaner, and if you need the time zone in the result you can put it into a character string pretty easily anyway. Allow fractional seconds in date/time types even for dates prior to 1BC. Limit timestamp data types to 6 decimal places of precision. Just right for a micro-second storage of int8 date/time types, and reduces the number of places ad-hoc rounding was occuring for the float8-based types. Use lookup tables for precision/rounding calculations for timestamp and interval types. Formerly used pow() to calculate the desired value but with a more limited range there is no reason to not type in a lookup table. Should be *much* better performance, though formerly there were some optimizations to help minimize the number of times pow() was called. Define a HAVE_INT64_TIMESTAMP variable. Based on the configure option "--enable-integer-datetimes" and the existing internal INT64_IS_BUSTED. Add explicit date/interval operators and functions for addition and subtraction. Formerly relied on implicit type promotion from date to timestamp with time zone. Change timezone conversion functions for the timetz type from "timetz()" to "timezone()". This is consistant with other time zone coersion functions for other types. Bump the catalog version to 200204201. Fix up regression tests to reflect changes in fractional seconds representation for date/times in BC eras. All regression tests pass on my Linux box. --- diff --git a/src/test/regress/expected/horology.out b/src/test/regress/expected/horology.out index bcace859ce..4315019210 100644 --- a/src/test/regress/expected/horology.out +++ b/src/test/regress/expected/horology.out @@ -264,22 +264,22 @@ SELECT date '2001-02-03' + time with time zone '04:05:06 UTC' AS "Date + Time UT (1 row) SELECT date '1991-02-03' + interval '2 years' AS "Add Two Years"; - Add Two Years ------------------------------- - Wed Feb 03 00:00:00 1993 PST + Add Two Years +-------------------------- + Wed Feb 03 00:00:00 1993 (1 row) SELECT date '2001-12-13' - interval '2 years' AS "Subtract Two Years"; - Subtract Two Years ------------------------------- - Mon Dec 13 00:00:00 1999 PST + Subtract Two Years +-------------------------- + Mon Dec 13 00:00:00 1999 (1 row) -- subtract time from date should not make sense; use interval instead SELECT date '1991-02-03' - time '04:05:06' AS "Subtract Time"; - Subtract Time ------------------------------- - Sat Feb 02 19:54:54 1991 PST + Subtract Time +-------------------------- + Sat Feb 02 19:54:54 1991 (1 row) SELECT date '1991-02-03' - time with time zone '04:05:06 UTC' AS "Subtract Time UTC"; @@ -406,7 +406,7 @@ SELECT '' AS "64", d1 + interval '1 year' AS one_year FROM TIMESTAMP_TBL; | Sat Feb 14 17:32:01 1998 | Sun Feb 15 17:32:01 1998 | Mon Feb 16 17:32:01 1998 - | Thu Feb 16 17:32 0096 BC + | Thu Feb 16 17:32:01 0096 BC | Sun Feb 16 17:32:01 0098 | Fri Feb 16 17:32:01 0598 | Wed Feb 16 17:32:01 1098 @@ -475,7 +475,7 @@ SELECT '' AS "64", d1 - interval '1 year' AS one_year FROM TIMESTAMP_TBL; | Wed Feb 14 17:32:01 1996 | Thu Feb 15 17:32:01 1996 | Fri Feb 16 17:32:01 1996 - | Mon Feb 16 17:32 0098 BC + | Mon Feb 16 17:32:01 0098 BC | Thu Feb 16 17:32:01 0096 | Tue Feb 16 17:32:01 0596 | Sun Feb 16 17:32:01 1096 @@ -622,7 +622,7 @@ SELECT '' AS "64", d1 + interval '1 year' AS one_year FROM TIMESTAMPTZ_TBL; | Sat Feb 14 17:32:01 1998 PST | Sun Feb 15 17:32:01 1998 PST | Mon Feb 16 17:32:01 1998 PST - | Thu Feb 16 17:32 0096 BC + | Thu Feb 16 17:32:01 0096 BC | Sun Feb 16 17:32:01 0098 | Fri Feb 16 17:32:01 0598 | Wed Feb 16 17:32:01 1098 @@ -691,7 +691,7 @@ SELECT '' AS "64", d1 - interval '1 year' AS one_year FROM TIMESTAMPTZ_TBL; | Wed Feb 14 17:32:01 1996 PST | Thu Feb 15 17:32:01 1996 PST | Fri Feb 16 17:32:01 1996 PST - | Mon Feb 16 17:32 0098 BC + | Mon Feb 16 17:32:01 0098 BC | Thu Feb 16 17:32:01 0096 | Tue Feb 16 17:32:01 0596 | Sun Feb 16 17:32:01 1096 @@ -1519,7 +1519,7 @@ SELECT (time '00:00', interval '1 hour') f (1 row) -CREATE TABLE TEMP_TIMESTAMP (f1 timestamp); +CREATE TABLE TEMP_TIMESTAMP (f1 timestamp with time zone); -- get some candidate input values INSERT INTO TEMP_TIMESTAMP (f1) SELECT d1 FROM TIMESTAMP_TBL @@ -1883,8 +1883,9 @@ SELECT '' AS "160", d.f1 AS "timestamp", t.f1 AS "interval", d.f1 - t.f1 AS minu | Sat Sep 22 18:19:20 2001 PDT | @ 14 secs ago | Sat Sep 22 18:19:34 2001 PDT (160 rows) -SELECT '' AS "16", d.f1 AS "timestamp", timestamp '1980-01-06 00:00 GMT' AS gpstime_zero, - d.f1 - timestamp '1980-01-06 00:00 GMT' AS difference +SELECT '' AS "16", d.f1 AS "timestamp", + timestamp with time zone '1980-01-06 00:00 GMT' AS gpstime_zero, + d.f1 - timestamp with time zone '1980-01-06 00:00 GMT' AS difference FROM TEMP_TIMESTAMP d ORDER BY difference; 16 | timestamp | gpstime_zero | difference @@ -2305,7 +2306,7 @@ SELECT '' AS two, d1 AS "timestamp", abstime(d1) AS abstime SELECT '' AS three, f1 as abstime, cast(f1 as timestamp) AS "timestamp" FROM ABSTIME_TBL WHERE NOT isfinite(f1); -ERROR: Unable to convert abstime 'invalid' to timestamptz +ERROR: Unable to convert abstime 'invalid' to timestamp SELECT '' AS ten, f1 AS interval, reltime(f1) AS reltime FROM INTERVAL_TBL; ten | interval | reltime @@ -2385,7 +2386,7 @@ SELECT '' AS "64", d1 AS us_postgres FROM TIMESTAMP_TBL; | Fri Feb 14 17:32:01 1997 | Sat Feb 15 17:32:01 1997 | Sun Feb 16 17:32:01 1997 - | Tue Feb 16 17:32 0097 BC + | Tue Feb 16 17:32:01 0097 BC | Sat Feb 16 17:32:01 0097 | Thu Feb 16 17:32:01 0597 | Tue Feb 16 17:32:01 1097 @@ -2467,7 +2468,7 @@ SELECT '' AS "64", d1 AS us_iso FROM TIMESTAMP_TBL; | 1997-02-14 17:32:01 | 1997-02-15 17:32:01 | 1997-02-16 17:32:01 - | 0097-02-16 17:32 BC + | 0097-02-16 17:32:01 BC | 0097-02-16 17:32:01 | 0597-02-16 17:32:01 | 1097-02-16 17:32:01 @@ -2551,7 +2552,7 @@ SELECT '' AS "64", d1 AS us_sql FROM TIMESTAMP_TBL; | 02/14/1997 17:32:01 | 02/15/1997 17:32:01 | 02/16/1997 17:32:01 - | 02/16/0097 17:32 BC + | 02/16/0097 17:32:01 BC | 02/16/0097 17:32:01 | 02/16/0597 17:32:01 | 02/16/1097 17:32:01 @@ -2642,7 +2643,7 @@ SELECT '' AS "65", d1 AS european_postgres FROM TIMESTAMP_TBL; | Fri 14 Feb 17:32:01 1997 | Sat 15 Feb 17:32:01 1997 | Sun 16 Feb 17:32:01 1997 - | Tue 16 Feb 17:32 0097 BC + | Tue 16 Feb 17:32:01 0097 BC | Sat 16 Feb 17:32:01 0097 | Thu 16 Feb 17:32:01 0597 | Tue 16 Feb 17:32:01 1097 @@ -2727,7 +2728,7 @@ SELECT '' AS "65", d1 AS european_iso FROM TIMESTAMP_TBL; | 1997-02-14 17:32:01 | 1997-02-15 17:32:01 | 1997-02-16 17:32:01 - | 0097-02-16 17:32 BC + | 0097-02-16 17:32:01 BC | 0097-02-16 17:32:01 | 0597-02-16 17:32:01 | 1097-02-16 17:32:01 @@ -2812,7 +2813,7 @@ SELECT '' AS "65", d1 AS european_sql FROM TIMESTAMP_TBL; | 14/02/1997 17:32:01 | 15/02/1997 17:32:01 | 16/02/1997 17:32:01 - | 16/02/0097 17:32 BC + | 16/02/0097 17:32:01 BC | 16/02/0097 17:32:01 | 16/02/0597 17:32:01 | 16/02/1097 17:32:01 diff --git a/src/test/regress/expected/timestamp.out b/src/test/regress/expected/timestamp.out index ad2f1d7ec9..e7c8cc8086 100644 --- a/src/test/regress/expected/timestamp.out +++ b/src/test/regress/expected/timestamp.out @@ -183,7 +183,7 @@ SELECT '' AS "64", d1 FROM TIMESTAMP_TBL; | Fri Feb 14 17:32:01 1997 | Sat Feb 15 17:32:01 1997 | Sun Feb 16 17:32:01 1997 - | Tue Feb 16 17:32 0097 BC + | Tue Feb 16 17:32:01 0097 BC | Sat Feb 16 17:32:01 0097 | Thu Feb 16 17:32:01 0597 | Tue Feb 16 17:32:01 1097 @@ -265,11 +265,11 @@ SELECT '' AS "48", d1 FROM TIMESTAMP_TBL SELECT '' AS "15", d1 FROM TIMESTAMP_TBL WHERE d1 < timestamp without time zone '1997-01-02'; - 15 | d1 -----+-------------------------- + 15 | d1 +----+----------------------------- | -infinity | Thu Jan 01 00:00:00 1970 - | Tue Feb 16 17:32 0097 BC + | Tue Feb 16 17:32:01 0097 BC | Sat Feb 16 17:32:01 0097 | Thu Feb 16 17:32:01 0597 | Tue Feb 16 17:32:01 1097 @@ -335,7 +335,7 @@ SELECT '' AS "63", d1 FROM TIMESTAMP_TBL | Fri Feb 14 17:32:01 1997 | Sat Feb 15 17:32:01 1997 | Sun Feb 16 17:32:01 1997 - | Tue Feb 16 17:32 0097 BC + | Tue Feb 16 17:32:01 0097 BC | Sat Feb 16 17:32:01 0097 | Thu Feb 16 17:32:01 0597 | Tue Feb 16 17:32:01 1097 @@ -362,12 +362,12 @@ SELECT '' AS "63", d1 FROM TIMESTAMP_TBL SELECT '' AS "16", d1 FROM TIMESTAMP_TBL WHERE d1 <= timestamp without time zone '1997-01-02'; - 16 | d1 -----+-------------------------- + 16 | d1 +----+----------------------------- | -infinity | Thu Jan 01 00:00:00 1970 | Thu Jan 02 00:00:00 1997 - | Tue Feb 16 17:32 0097 BC + | Tue Feb 16 17:32:01 0097 BC | Sat Feb 16 17:32:01 0097 | Thu Feb 16 17:32:01 0597 | Tue Feb 16 17:32:01 1097 diff --git a/src/test/regress/expected/timestamptz.out b/src/test/regress/expected/timestamptz.out index 1741add0ac..403a0bbd4a 100644 --- a/src/test/regress/expected/timestamptz.out +++ b/src/test/regress/expected/timestamptz.out @@ -178,7 +178,7 @@ SELECT '' AS "64", d1 FROM TIMESTAMPTZ_TBL; | Fri Feb 14 17:32:01 1997 PST | Sat Feb 15 17:32:01 1997 PST | Sun Feb 16 17:32:01 1997 PST - | Tue Feb 16 17:32 0097 BC + | Tue Feb 16 17:32:01 0097 BC | Sat Feb 16 17:32:01 0097 | Thu Feb 16 17:32:01 0597 | Tue Feb 16 17:32:01 1097 @@ -264,7 +264,7 @@ SELECT '' AS "15", d1 FROM TIMESTAMPTZ_TBL ----+------------------------------ | -infinity | Wed Dec 31 16:00:00 1969 PST - | Tue Feb 16 17:32 0097 BC + | Tue Feb 16 17:32:01 0097 BC | Sat Feb 16 17:32:01 0097 | Thu Feb 16 17:32:01 0597 | Tue Feb 16 17:32:01 1097 @@ -330,7 +330,7 @@ SELECT '' AS "63", d1 FROM TIMESTAMPTZ_TBL | Fri Feb 14 17:32:01 1997 PST | Sat Feb 15 17:32:01 1997 PST | Sun Feb 16 17:32:01 1997 PST - | Tue Feb 16 17:32 0097 BC + | Tue Feb 16 17:32:01 0097 BC | Sat Feb 16 17:32:01 0097 | Thu Feb 16 17:32:01 0597 | Tue Feb 16 17:32:01 1097 @@ -362,7 +362,7 @@ SELECT '' AS "16", d1 FROM TIMESTAMPTZ_TBL | -infinity | Wed Dec 31 16:00:00 1969 PST | Thu Jan 02 00:00:00 1997 PST - | Tue Feb 16 17:32 0097 BC + | Tue Feb 16 17:32:01 0097 BC | Sat Feb 16 17:32:01 0097 | Thu Feb 16 17:32:01 0597 | Tue Feb 16 17:32:01 1097 diff --git a/src/test/regress/sql/horology.sql b/src/test/regress/sql/horology.sql index 019c3e9ffd..136e6c6c65 100644 --- a/src/test/regress/sql/horology.sql +++ b/src/test/regress/sql/horology.sql @@ -214,7 +214,7 @@ SELECT (time '00:00', interval '1 hour') SELECT (time '00:00', interval '1 hour') OVERLAPS (time '01:30', interval '1 day') AS "False"; -CREATE TABLE TEMP_TIMESTAMP (f1 timestamp); +CREATE TABLE TEMP_TIMESTAMP (f1 timestamp with time zone); -- get some candidate input values @@ -236,8 +236,9 @@ SELECT '' AS "160", d.f1 AS "timestamp", t.f1 AS "interval", d.f1 - t.f1 AS minu WHERE isfinite(d.f1) ORDER BY minus, "timestamp", "interval"; -SELECT '' AS "16", d.f1 AS "timestamp", timestamp '1980-01-06 00:00 GMT' AS gpstime_zero, - d.f1 - timestamp '1980-01-06 00:00 GMT' AS difference +SELECT '' AS "16", d.f1 AS "timestamp", + timestamp with time zone '1980-01-06 00:00 GMT' AS gpstime_zero, + d.f1 - timestamp with time zone '1980-01-06 00:00 GMT' AS difference FROM TEMP_TIMESTAMP d ORDER BY difference;