8.3 vs HEAD difference in Interval output? - Mailing list pgsql-hackers

From R Mayer
Subject 8.3 vs HEAD difference in Interval output?
Date
Msg-id 48CED552.4050003@cheapcomplexdevices.com
Whole thread Raw
In response to Re: Proposed patch: make SQL interval-literal syntax work per spec  (Ron Mayer <rm_pg@cheapcomplexdevices.com>)
List pgsql-hackers
Unless I'm compiling stuff wrong, it seems HEAD is giving me
slightly different output on Intervals than 8.3 in the roundoff
of seconds.   8.3 was rounding to the nearest fraction of a second,
HEAD seems to be truncating.

In the psql output below it shows 8.3.1 outputting "6.70 secs"
while the similar output for head is showing "6.69 secs".

At first glance it seems this might be because HEAD defaults
to USE_INTEGER_DATETIMES, which leads to HAVE_INT64_TIMESTAMP
which leads to  sprintf(cp, "%s%d.%02d secs", is_nonzero ? " " : "",  tm->tm_sec, ((int) sec) / 10000);
in EncodeInterval in datetime.c which doesn't seem to be
doing any rounding.

Am I interpreting this right?  If so, shall I submit a patch
that rounds it to hundredths of a second (hundredths seems
hardcoded in the sprintf), or perhaps just silently add that
fix to the EncodeInterval patch I'm doing any for SQL Standard
and ISO intervals?



========================================================================
psql (8.4devel)
Type "help" for help.
regression=# set datestyle to sql;
SET
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)

========================================================================
Welcome to psql 8.3.1, the PostgreSQL interactive terminal.
...
pg83=# set datestyle to sql;
SET
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)


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: 8.3 vs HEAD difference in Interval output?
Next
From: Ron Mayer
Date:
Subject: Re: 8.3 vs HEAD difference in Interval output?