Index: src/backend/utils/adt/timestamp.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v retrieving revision 1.160 diff --context=5 -r1.160 timestamp.c *** src/backend/utils/adt/timestamp.c 22 Nov 2005 22:30:33 -0000 1.160 --- src/backend/utils/adt/timestamp.c 1 Mar 2006 22:29:32 -0000 *************** *** 2003,2013 **** TMODULO(result->time, wholeday, USECS_PER_DAY); #else TMODULO(result->time, wholeday, (double) SECS_PER_DAY); #endif result->day += wholeday; /* could overflow... */ ! PG_RETURN_INTERVAL_P(result); } /* * interval_justify_days() --- 2003,2024 ---- TMODULO(result->time, wholeday, USECS_PER_DAY); #else TMODULO(result->time, wholeday, (double) SECS_PER_DAY); #endif result->day += wholeday; /* could overflow... */ ! if ((result->time < 0) && ! ((result->month >= 0 && result->day >= 0) || ! (result->month > 0 && result->day < 0 && (-1.0 * (double)result->day)/((double)result->month) < ((double)DAYS_PER_MONTH)) || ! (result->month < 0 && result->day > 0 && ((double)result->day)/(-1.0 * (double)result->month) > ((double)DAYS_PER_MONTH)))) ! { ! #ifdef HAVE_INT64_TIMESTAMP ! result->time += USECS_PER_DAY; ! #else ! result->time += (double) SECS_PER_DAY; ! #endif ! result->day--; ! } PG_RETURN_INTERVAL_P(result); } /* * interval_justify_days() *************** *** 2028,2037 **** --- 2039,2053 ---- result->time = span->time; wholemonth = result->day / DAYS_PER_MONTH; result->day -= wholemonth * DAYS_PER_MONTH; result->month += wholemonth; + if (result->day < 0 && result->month > 0) + { + result->day += DAYS_PER_MONTH; + result->month--; + } PG_RETURN_INTERVAL_P(result); } /* timestamp_pl_interval()