Re: truncating timestamps on arbitrary intervals

From: Artur Zakirov <zaartur(at)gmail(dot)com>
To: John Naylor <john(dot)naylor(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: David Fetter <david(at)fetter(dot)org>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: truncating timestamps on arbitrary intervals
Date: 2020-03-19 08:20:55
Message-ID: a389a68b-27f3-0554-3c5d-8f03a1dee530@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello,

On 3/13/2020 4:13 PM, John Naylor wrote:
> I've put off adding documentation on the origin piece pending comments
> about the approach.
>
> I haven't thought seriously about timezone yet, but hopefully it's
> just work and nothing to think too hard about.

Thank you for the patch. I looked it and tested a bit.

There is one interesting case which might be mentioned in the
documentation or in the tests is the following. The function has
interesting behaviour with real numbers:

=# select date_trunc_interval('0.1 year'::interval, TIMESTAMP
'2020-02-01 01:21:01');
date_trunc_interval
---------------------
2020-02-01 00:00:00

=# select date_trunc_interval('1.1 year'::interval, TIMESTAMP
'2020-02-01 01:21:01');
ERROR: only one interval unit allowed for truncation

It is because the second interval has two interval units:

=# select '0.1 year'::interval;
interval
----------
1 mon

=# select '1.1 year'::interval;
interval
--------------
1 year 1 mon

--
Artur

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2020-03-19 08:21:38 Re: pg_stat_progress_basebackup - progress reporting for pg_basebackup, in the server side
Previous Message asaba.takanori@fujitsu.com 2020-03-19 08:10:58 RE: ssl passphrase callback