Re: several cases of float and integer mixup

From: Dave Sharpe <davesharpe13(at)gmail(dot)com>
To: Peter Eisentraut <peter(at)eisentraut(dot)org>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: several cases of float and integer mixup
Date: 2026-12-03 12:51:37
Message-ID: CAKFmFJ8eWtyty=ng0xpeMSKKZyrpKsFJ=2BX-MygLxWvPrrbPg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Peter,

On Thu, 3 Dec 2026 at 06:06, Peter Eisentraut <peter(at)eisentraut(dot)org> wrote:
> I have found several cases where a variable or C function argument was
> declared as an integer but should be a floating-point type, or vice
> versa. See attached patches. I think most of these are harmless in
> practice.

Regarding 0005 (ecpg dt2time): agreed, it doesn't change behaviour.
But seeing an explicit double to int64 cast, that truncates,
which can lose a microsecond. The backend does the same thing in
DecodeDateTime() (at the dt2time() call), so it is easy to
show from SQL. For example, 0.7 of a day is exactly 16:48:00, but:

SELECT 'J2451187.7'::timestamp;
1999-01-08 16:47:59.999999

SELECT 'J2451187'::timestamp + '0.7 day'::interval;
1999-01-08 16:48:00

SELECT '0.7 day'::interval;
16:48:00

Both paths start from the same double:
0.7 * USECS_PER_DAY = 60479999999.99999. The interval code
(AdjustFractMicroseconds()) rounds it, while the Julian-day code
truncates it.

Applying the interval code's idea to the Julian-day path would be
something like:

time = rint(time * USECS_PER_DAY);
dt2time((Timestamp) time, ...);

Unlike 0005, that changes results, although towards the correct answer.
Is that worth exploring (on a separate thread)?

Regards,
Dave Sharpe

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeevan Chalke 2026-12-03 12:52:30 CRASH: use-after-free of function stats when a procedure rolls back its own CREATE
Previous Message Kirill Reshke 2026-12-03 12:35:33 Re: several cases of float and integer mixup