1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-16 06:01:02 +03:00

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.
This commit is contained in:
Thomas G. Lockhart
2001-10-20 01:02:22 +00:00
parent 3a484d9e99
commit 424d9389d6
6 changed files with 114 additions and 57 deletions

View File

@ -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;
}