Seems to me there's a bug in HEAD (and probably old branches
as well) when compiled with HAVE_INT64_TIMESTAMP. As shown below
It sometimes shows things like "-6.-70 secs" where 8.3
showed "-6.70 secs".
I think the attached one-liner patch fixes this, as well as
another roundoff regression between HEAD and 8.3.
Ron Mayer
================================================================================
== ON HEAD
================================================================================
regression=# set datestyle to sql;
SET
regression=# select '-10 mons -3 days +03:55:06.70'::interval;
interval
----------------------------------------------------
@ 10 mons 3 days -3 hours -55 mins -6.-70 secs ago
(1 row)
regression=# select '1 year 2 mons 3 days 04:05:06.699999'::interval;
interval
-------------------------------------------------
@ 1 year 2 mons 3 days 4 hours 5 mins 6.69 secs
(1 row)
================================================================================
== ON 8.3
================================================================================
pg83=# set datestyle to sql;
SET
pg83=# select '-10 mons -3 days +03:55:06.70'::interval;
interval
---------------------------------------------------
@ 10 mons 3 days -3 hours -55 mins -6.70 secs ago
(1 row)
pg83=# select '1 year 2 mons 3 days 04:05:06.699999'::interval;
interval
-------------------------------------------------
@ 1 year 2 mons 3 days 4 hours 5 mins 6.70 secs
(1 row)
*** a/src/backend/utils/adt/datetime.c
--- b/src/backend/utils/adt/datetime.c
***************
*** 3791,3797 **** EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
is_before = TRUE;
}
sprintf(cp, "%s%d.%02d secs", is_nonzero ? " " : "",
! tm->tm_sec, ((int) sec) / 10000);
cp += strlen(cp);
#else
fsec += tm->tm_sec;
--- 3791,3797 ----
is_before = TRUE;
}
sprintf(cp, "%s%d.%02d secs", is_nonzero ? " " : "",
! tm->tm_sec, (int) abs(rint(sec / 10000.0)));
cp += strlen(cp);
#else
fsec += tm->tm_sec;