From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Bryn Llewellyn <bryn@yugabyte.com>
To: Ken Tanzer <ken.tanzer@gmail.com>
Cc: Tom Lane PostgreSQL <tgl@sss.pgh.pa.us>
Cc: david.g.johnston@gmail.com, Sebastien Flaesch <sebastien.flaesch@4js.com>
Cc: pgsql-general list <pgsql-general@lists.postgresql.org>
Subject: Re: Intervals and ISO 8601 duration
Date: Fri, 13 Jan 2023 16:08:41 -0800
Message-ID: <c34000c0-dc7a-d711-b20f-6670fe033692@aklaver.com> (raw)
In-Reply-To: <ECC4DF67-6FB3-43D2-B9B6-CB41290F68A8@yugabyte.com>
References: <AM9P191MB1286AD77B5FBAF4640E7274AB0FD9@AM9P191MB1286.EURP191.PROD.OUTLOOK.COM>
<953416.1673536094@sss.pgh.pa.us>
<CAD3a31XW8iqrZ+uB7if+YUgRjk_=9YQOJRJVBc5__yGRsgypQA@mail.gmail.com>
<53c0b4d4-b80a-a35b-ce18-61058794c9bb@aklaver.com>
<CAD3a31UP79wrZZTRFtP4sPvgOy7TZg2v6FmPzXYdAAnaOdnuiQ@mail.gmail.com>
<ECC4DF67-6FB3-43D2-B9B6-CB41290F68A8@yugabyte.com>
On 1/13/23 16:03, Bryn Llewellyn wrote:
>> ken.tanzer@gmail.com <mailto:ken.tanzer@gmail.com> wrote:
>>
> I struggled to understand this whole murky area when I was writing the
> “Date and time data types and functionality” section for the YugabyteDB
> doc. (YugabyteDB uses the Postgres SQL processing code “as is” on top of
> its own distributed storage layer. All the examples in my doc work
> identically in vanilla PG.)
>
> The implied question here is this: is the interval “1 day 2 hours” the
> same as the interval “26 hours”? It might seem that the answer is
> “yes”—as it surely must be. But, sorry to say, that the answer is
> actually “no”. Confused? You will be. Most people are until they’ve
> wrapped their head in a towel and puzzled it through for a few days.
Or read the docs:
https://www.postgresql.org/docs/current/datatype-datetime.html#DATATYPE-INTERVAL-OUTPUT
"Internally interval values are stored as months, days, and
microseconds. This is done because the number of days in a month varies,
and a day can have 23 or 25 hours if a daylight savings time adjustment
is involved."
> This shows you what I mean:
>
> set timezone = 'America/Los_Angeles';
> with c as (
> select '2023-03-11 20:00 America/Los_Angeles'::timestamptz as
> original_appointment)
> select
> original_appointment::text as "original appointment",
> (original_appointment + '1 day 2 hours'::interval)::text as
> "postponed by '1_day 2 hours'",
> (original_appointment + '26 hours'::interval)::text as "postponed by
> '24_hours'"
> from c;
>
> This is the result:
>
> original appointment | postponed by '1_day 2 hours' | postponed by
> '24_hours'
> ------------------------+------------------------------+-------------------------
> 2023-03-11 20:00:00-08 | 2023-03-12 22:00:00-07 | 2023-03-12
> 23:00:00-07
>
> Two different answers! The “trick” here is that the time of the original
> appointment and the postponed times straddle the 2023 “spring forward”
> moment (at least as it happens in the America/Los_Angeles timezone). And
> the resolution of what at first might seem to be a bug come when you
> realized that you must make a distinction between clock time and
> calendar time.
--
Adrian Klaver
adrian.klaver@aklaver.com
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: adrian.klaver@aklaver.com, bryn@yugabyte.com, ken.tanzer@gmail.com, tgl@sss.pgh.pa.us, sebastien.flaesch@4js.com
Subject: Re: Intervals and ISO 8601 duration
In-Reply-To: <c34000c0-dc7a-d711-b20f-6670fe033692@aklaver.com>
References: <AM9P191MB1286AD77B5FBAF4640E7274AB0FD9@AM9P191MB1286.EURP191.PROD.OUTLOOK.COM> <953416.1673536094@sss.pgh.pa.us> <CAD3a31XW8iqrZ+uB7if+YUgRjk_=9YQOJRJVBc5__yGRsgypQA@mail.gmail.com> <53c0b4d4-b80a-a35b-ce18-61058794c9bb@aklaver.com> <CAD3a31UP79wrZZTRFtP4sPvgOy7TZg2v6FmPzXYdAAnaOdnuiQ@mail.gmail.com> <ECC4DF67-6FB3-43D2-B9B6-CB41290F68A8@yugabyte.com> <c34000c0-dc7a-d711-b20f-6670fe033692@aklaver.com>
* 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