From: Tom Lane <tgl@sss.pgh.pa.us>
To: Bryn Llewellyn <bryn@yugabyte.com>
Cc: pgsql-general list <pgsql-general@lists.postgresql.org>
Subject: Re: i := t1 - t0 but t0 + i <> t1 when t1 and t2 timestamptz values and i is an interval value
Date: Fri, 26 Mar 2021 09:36:06 -0400
Message-ID: <1578541.1616765766@sss.pgh.pa.us> (raw)
In-Reply-To: <402F8EFB-3FE9-421A-B3BA-F736AB8E3ABB@yugabyte.com>
References: <402F8EFB-3FE9-421A-B3BA-F736AB8E3ABB@yugabyte.com>
Bryn Llewellyn <bryn@yugabyte.com> writes:
> There's more. We see that while the two "interval second” values '1 day 01:00:00' and '25 hours' test as equal, the results of adding each to the same timestamptz value are different.
You're misunderstanding how it works. The whole point of these
operations is that "+ '1 day'" should give the same civil time
on the next day, even if a DST boundary intervened. Similarly,
"+ '1 month'" tries to give the same day number in the next
month, and "+ '1 year'" tries to give the same month/day in the
next year, despite varying month and year lengths. (Obviously,
there are edge cases where there is no such date, and you get some
nearby date instead.) Smaller units are taken literally though,
so you could add some large number of hours or seconds if you
don't want these behaviors.
> PLEASE STATE THE RULES THAT ALLOW THE BEHAVIOR OF THE BLOCK TO BE PREDICTED.
If you are looking for simple predictable rules, I am afraid
there is absolutely nothing about either the Gregorian calendar
or daylight-savings time that you will like.
> (I searched the doc but found nothing.)
There's a specific discussion of the DST-boundary issue on
this page:
https://www.postgresql.org/docs/current/functions-datetime.html
(search for the first mention of America/Denver). Not sure about
how well the months and years cases are documented.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, bryn@yugabyte.com
Subject: Re: i := t1 - t0 but t0 + i <> t1 when t1 and t2 timestamptz values and i is an interval value
In-Reply-To: <1578541.1616765766@sss.pgh.pa.us>
References: <402F8EFB-3FE9-421A-B3BA-F736AB8E3ABB@yugabyte.com> <1578541.1616765766@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox