Re: truncating timestamps on arbitrary intervals
Artur Zakirov <zaartur@gmail.com>
From: Artur Zakirov <zaartur@gmail.com>
To: John Naylor <john.naylor@2ndquadrant.com>, Tom Lane <tgl@sss.pgh.pa.us>
Cc: David Fetter <david@fetter.org>,
PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2020-03-19T08:20:55Z
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
Commits
-
Disallow negative strides in date_bin()
- fc0d9b8c224f 14.0 landed
- 3ba70d4e1523 15.0 landed
-
Improve behavior of date_bin with origin in the future
- 496e58bb0e5e 14.0 landed
-
doc: Additional documentation for date_bin
- 49fb4e6b2490 14.0 landed
-
Add date_bin function
- 49ab61f0bdc9 14.0 landed