I working on the 'date' interval patch, I found a bug in handling of interval division and multiplication. Look at this:
test=> select '4 months'::interval / 5; ?column? --------------- 1 mon -6 days (1 row) With the attached fix, it returns the right value: test=> select '4 months'::interval / 5; ?column? ---------- 24 days (1 row) The bug is the use of rint() to round the division, but then using the rounded value to find the remainder to pass down to the time field. The attached patch has been applied to current CVS. Should I backpatch this fix? -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073
Index: src/backend/utils/adt/timestamp.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v retrieving revision 1.132 diff -c -c -r1.132 timestamp.c *** src/backend/utils/adt/timestamp.c 12 Jul 2005 16:04:58 -0000 1.132 --- src/backend/utils/adt/timestamp.c 20 Jul 2005 03:38:52 -0000 *************** *** 2201,2207 **** result->time += (months - result->month) * INT64CONST(30) * USECS_PER_DAY; #else ! result->month = rint(months); result->time = JROUND(span1->time * factor); /* evaluate fractional months as 30 days */ result->time += JROUND((months - result->month) * 30 * SECS_PER_DAY); --- 2201,2207 ---- result->time += (months - result->month) * INT64CONST(30) * USECS_PER_DAY; #else ! result->month = (int)months; result->time = JROUND(span1->time * factor); /* evaluate fractional months as 30 days */ result->time += JROUND((months - result->month) * 30 * SECS_PER_DAY); *************** *** 2246,2252 **** INT64CONST(30) * USECS_PER_DAY) / factor; #else months = span->month / factor; ! result->month = rint(months); result->time = JROUND(span->time / factor); /* evaluate fractional months as 30 days */ result->time += JROUND((months - result->month) * 30 * SECS_PER_DAY); --- 2246,2252 ---- INT64CONST(30) * USECS_PER_DAY) / factor; #else months = span->month / factor; ! result->month = (int)months; result->time = JROUND(span->time / factor); /* evaluate fractional months as 30 days */ result->time += JROUND((months - result->month) * 30 * SECS_PER_DAY);
---------------------------(end of broadcast)--------------------------- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match