diff options
author | Thomas G. Lockhart <lockhart@fourpalms.org> | 2001-10-20 01:02:22 +0000 |
---|---|---|
committer | Thomas G. Lockhart <lockhart@fourpalms.org> | 2001-10-20 01:02:22 +0000 |
commit | 424d9389d61997266aa17dec7ac8247a2459fdef (patch) | |
tree | 39e997c31de025e9aaa051c75b2fa5e1d1257bd9 /src/backend/utils/adt/timestamp.c | |
parent | 3a484d9e99f8ac6e757a09b65e376a8f6f3a0920 (diff) | |
download | postgresql-424d9389d61997266aa17dec7ac8247a2459fdef.tar.gz postgresql-424d9389d61997266aa17dec7ac8247a2459fdef.zip |
Fix transposed arguments for typmod for one INTERVAL production.
Mask both typmod subfields for INTERVAL to avoid setting the high bit,
per dire warning from Tom Lane.
Clear tmask for DTK_ISO_TIME case to avoid time zone troubles.
Symptom reported by Tom Lane.
Clean up checking for valid time zone info in output routine.
This should now work for both SQL99 and Unix-style time zones.
Put in explicit check for INTERVAL() typmod rounding to avoid accumulating
cruft in the lower bits. Not sure that this helps, but we'll need to do
something. The symptom is visible with a query like
select interval(2) '10000 days 01:02:03.040506';
Regression tests are patched to repair the Tom Lane symptom, and all pass.
Diffstat (limited to 'src/backend/utils/adt/timestamp.c')
-rw-r--r-- | src/backend/utils/adt/timestamp.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index efe4a501463..f39e85b235e 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.57 2001/10/18 19:54:59 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.58 2001/10/20 01:02:18 thomas Exp $ * *------------------------------------------------------------------------- */ @@ -374,14 +374,14 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod) { if (typmod != -1) { - int range = ((typmod >> 16) & 0xFFFF); + int range = ((typmod >> 16) & 0x7FFF); int precision = (typmod & 0xFFFF); - if (range == 0xFFFF) + if (range == 0x7FFF) { /* Do nothing... */ } - if (range == MASK(YEAR)) + else if (range == MASK(YEAR)) { interval->month = ((interval->month / 12) * 12); interval->time = 0; @@ -483,7 +483,18 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod) IntervalScale = pow(10.0, IntervalTypmod); } - interval->time = (rint(interval->time * IntervalScale) / IntervalScale); + /* Hmm. For the time field, we can get to a large value + * since we store everything related to an absolute interval + * (e.g. years worth of days) in this one field. So we have + * precision problems doing rint() on this field if the field + * is too large. This resulted in an annoying "...0001" appended + * to the printed result on my Linux box. + * I hate doing an expensive math operation like log10() + * to avoid this, but what else can we do?? + * - thomas 2001-10-19 + */ + if ((log10(interval->time) + IntervalTypmod) <= 13) + interval->time = (rint(interval->time * IntervalScale) / IntervalScale); } } @@ -671,14 +682,15 @@ timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, double *fsec, char **tzn) else { *tzp = 0; - tm->tm_isdst = 0; + /* Mark this as *no* time zone available */ + tm->tm_isdst = -1; if (tzn != NULL) *tzn = NULL; } } else { - tm->tm_isdst = 0; + tm->tm_isdst = -1; if (tzn != NULL) *tzn = NULL; } |