Re: truncating timestamps on arbitrary intervals - Mailing list pgsql-hackers

From Artur Zakirov
Subject Re: truncating timestamps on arbitrary intervals
Date
Msg-id 930846e3-32c7-c1e3-bfdd-873ac716fbe4@gmail.com
Whole thread Raw
In response to Re: truncating timestamps on arbitrary intervals  (John Naylor <john.naylor@2ndquadrant.com>)
Responses Re: truncating timestamps on arbitrary intervals  (John Naylor <john.naylor@2ndquadrant.com>)
List pgsql-hackers
On 3/30/2020 9:30 PM, John Naylor wrote:
> I attempted this in the attached v7. There are 4 new functions for
> truncating timestamptz on an interval -- with and without origin, and
> with and without time zone.

Thank you for new version of the patch.

I'm not sure that I fully understand the 'origin' parameter. Is it valid 
to have a value of 'origin' which is greater than a value of 'timestamp' 
parameter?

I get some different results in such case:

=# select date_trunc_interval('2 year', timestamp '2020-01-16 20:38:40', 
timestamp '2022-01-17 00:00:00');
  date_trunc_interval
---------------------
  2020-01-01 00:00:00

=# select date_trunc_interval('3 year', timestamp '2020-01-16 20:38:40', 
timestamp '2022-01-17 00:00:00');
  date_trunc_interval
---------------------
  2022-01-01 00:00:00

So here I'm not sure which result is correct.

It seems that the patch is still in progress, but I have some nitpicking.

> +        <entry><literal><function>date_trunc_interval(<type>interval</type>, <type>timestamptz</type>,
<type>text</type>)</function></literal></entry>
> +        <entry><type>timestamptz  </type></entry>

It seems that 'timestamptz' in both argument and result descriptions 
should be replaced by 'timestamp with time zone' (see other functions 
descriptions). Though it is okay to use 'timestamptz' in SQL examples.

timestamp_trunc_interval_internal() and 
timestamptz_trunc_interval_internal() have similar code. I think they 
can be rewritten to avoid code duplication.

-- 
Artur



pgsql-hackers by date:

Previous
From: Justin Pryzby
Date:
Subject: Re: pg11+: pg_ls_*dir LIMIT 1: temporary files .. not closed atend-of-transaction
Next
From: movead li
Date:
Subject: Re: recovery_target_action=pause with confusing hint