mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
Attached is a patch that limits the range tested by horology to
what is capable using integer-datatime timestamps. It does attempt
to exercise the maximum allowable timestamp range.
Also is a small error check when converting a timestamp from external
to internal format that prevents out of range timestamps from being
entered.
Files patched:
Index: src/backend/utils/adt/timestamp.c
Added range check to prevent out of range timestamps
from being used.
Index: src/test/regress/sql/horology.sql
Index: src/test/regress/expected/horology-no-DST-before-1970.out
Index: src/test/regress/expected/horology-solaris-1947.out
Limited range of timestamps being checked to
Jan 1, 4713 BC to Dec 31, 294276
In creating this patch, I have seen some definite problems with integer
timestamps and how they react when used near their limits. For example,
the following statement gives the correct result:
SELECT timestamp without time zone 'Jan 1, 4713 BC'
+ interval '109203489 days' AS "Dec 31, 294276";
However, this statement which is the logical inverse of the above
gives incorrect results:
SELECT timestamp without time zone '12/31/294276'
- timestamp without time zone 'Jan 1, 4713 BC' AS "109203489 Days";
John Cochran
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.80 2003/03/11 21:01:33 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.81 2003/03/20 06:02:59 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -964,6 +964,9 @@ tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, Timestamp *result)
|
||||
time = time2t(tm->tm_hour, tm->tm_min, tm->tm_sec, fsec);
|
||||
#ifdef HAVE_INT64_TIMESTAMP
|
||||
*result = ((date * INT64CONST(86400000000)) + time);
|
||||
if ((*result < 0 && date >= 0) || (*result >= 0 && date < 0))
|
||||
elog(ERROR, "TIMESTAMP out of range '%04d-%02d-%02d'",
|
||||
tm->tm_year, tm->tm_mon, tm->tm_mday);
|
||||
#else
|
||||
*result = ((date * 86400) + time);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user