I wouldn’t discuss the algorithm on this list. I’d just commit to being 
compatible with Postgres, and write a bunch of tests based on Postgres’ 
observed behavior. 

> On Sep 23, 2021, at 5:12 AM, Phillip Cloud <cpcl...@gmail.com> wrote:
> 
> Hi all,
> 
> I wanted to draw some attention to ARROW-11090 [1] in an effort to start
> getting the implementation going for temporal arithmetic kernels.
> 
> The supported operation matrix is decently large.
> 
> I would like to propose that we adopt the behavior of PostgreSQL where
> things are at first glance ambiguous, such as this operation:
> 
> SELECT DATE '2021-05-30' + INTERVAL '1' MONTH
> 
> I couldn't find any documentation about this specific case, but the code is
> fairly straightforward and has a useful comment describing the behavior
> [2]. The timestamp_pl_interval will first add 1 to the month number [3],
> and then take the minimum of the month day (in this case 31, for the
> non-existent date 2021-06-31 and the latest valid day in the month (the
> latest valid day being 30; month day counts are encoded as a table with two
> rows one for leap years one for non leap years [4]) [5].
> 
> Thoughts?
> 
> [1]: https://issues.apache.org/jira/browse/ARROW-11090
> [2]:
> https://github.com/postgres/postgres/blob/master/src/backend/utils/adt/timestamp.c#L2830-L2839
> [3]:
> https://github.com/postgres/postgres/blob/master/src/backend/utils/adt/timestamp.c#L2862
> [4]:
> https://github.com/postgres/postgres/blob/master/src/interfaces/ecpg/pgtypeslib/dt_common.c#L14-L16
> [5]:
> https://github.com/postgres/postgres/blob/master/src/backend/utils/adt/timestamp.c#L2874-L2876

Reply via email to