Re: Fix for edge case in date_bin() function

From: Moaaz Assali <ma5679(at)nyu(dot)edu>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Fix for edge case in date_bin() function
Date: 2024-02-29 06:53:42
Message-ID: CALkF+nt9V0WW9i3ezbZ3OrSxrS5__mr62burPPL_4ZAYwrTU_g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello Tom,

Thanks for the quick patch!

You're right. The stride_usecs calculation, tm_delta += ustride_usecs, and
final result calculations can overflow and need a guard.

However, I don't see the issue with the INT64 -> UINT64 mapping. The
current implementation results in integer overflows (errors instead after
the recent patch) even for valid timestamps where the result of date_bin()
is also another valid timestamp.

On the other hand, the INT64 -> UINT64 mapping solves this issue and allows
the input of any valid source and origin timestamps as long as the stride
chosen doesn't output invalid timestamps that cannot be represented by
Timestamp(tz) type anyways. Since all INT64 values can be mapped 1-to-1 in
UINT64, I don't see where the problem is.

Best regards,
Moaaz Assali

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bertrand Drouvot 2024-02-29 07:09:03 Re: Synchronizing slots from primary to standby
Previous Message Michael Paquier 2024-02-29 06:32:03 Re: DOCS: Avoid using abbreviation "aka"