pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Bryn Llewellyn <bryn@yugabyte.com>
To: Tom Lane PostgreSQL <tgl@sss.pgh.pa.us>
To: folarte@peoplecall.com
Cc: pgsql-general list <pgsql-general@lists.postgresql.org>
Subject: Re: = t1 - t0 but t0 + i <> t1 when t1 and t2 timestamptz values and i is an interval value
Date: Sat, 27 Mar 2021 09:16:30 -0700
Message-ID: <e8e1d2e4-1eca-d1c1-eaee-2081d1e40b56@aklaver.com> (raw)
In-Reply-To: <DAABCBE6-6DFF-4C28-9CED-0AA8053FE12C@yugabyte.com>
References: <402F8EFB-3FE9-421A-B3BA-F736AB8E3ABB@yugabyte.com>
	<1578541.1616765766@sss.pgh.pa.us>
	<DAABCBE6-6DFF-4C28-9CED-0AA8053FE12C@yugabyte.com>

On 3/26/21 2:16 PM, Bryn Llewellyn wrote:
> /Tom Lane wrote:/
> 

> Finally, I discovered that this is OK:
> 
> *create table t(i interval);*
> 
> But I can’t find a definition of the semantics of a bare interval. 
> However, I did find a column headed “Mixed Interval”  at 
> https://www.postgresql.org/docs/11/datatype-datetime.html#INTERVAL-STYLE-OUTPUT-TABLE 
> <https://www.postgresql.org/docs/11/datatype-datetime.html#INTERVAL-STYLE-OUTPUT-TABLE;. 
> But the example values in the column are consistent with this:
> 
> *select ((interval '2 years, 3 months, 4 days, 5 hours, 6 minutes 7.8 
> seconds')::interval)::text as i;*
> 
> This is the result:
> 
> *2 years 3 mons 4 days 05:06:07.8*
> 
> If you repeat the “select” using the typecast “*::interval month*” then 
> the other components are silently thrown away. But if you repeat it 
> using the typecast “*::interval second*” then all components are 
> preserved just as with bare “*interval*”. This muddies my idea that 
> there were three distinct interval flavors: horological, cultural, and 
> hybrid. Is the behavior that I’ve just shown intended?


https://www.postgresql.org/docs/current/datatype-datetime.html#DATATYPE-INTERVAL-INPUT

"Also, field values “to the right” of the least significant field 
allowed by the fields specification are silently discarded. For example, 
writing INTERVAL '1 day 2:03:04' HOUR TO MINUTE results in dropping the 
seconds field, but not the day field."

So you get:

test(5432)=> select '2 years 3 mons 4 days 05:06:07.8'::interval month;
     interval
----------------
  2 years 3 mons
(1 row)

Equivalent to:

test(5432)=> select '2 years 3 mons 4 days 05:06:07.8'::interval YEAR TO 
MONTH;
     interval
----------------
  2 years 3 mons


test(5432)=> select '2 years 3 mons 4 days 05:06:07.8'::interval second;
              interval
----------------------------------
  2 years 3 mons 4 days 05:06:07.8
(1 row)

Equivalent to:

select '2 years 3 mons 4 days 05:06:07.8'::interval HOUR TO SECOND;
              interval
----------------------------------
  2 years 3 mons 4 days 05:06:07.8
(1 row)

> 
> I can guess the rules for the outcome when such a hybrid is added to a 
> timestamptz value. It’s possible to design edge case tests where you’d 
> get different outcomes if: (a) the cultural component is added first and 
> only then the horological component is added; or (b) the components are 
> added in the other order. It seems to me that the outcome is governed by 
> rule (a). Am I right?
> 
> B.t.w., I think that the specific complexities of the proleptic 
> Gregorian calendar are cleanly separable from the basic idea that 
> (considering only the requirements statement space) there is a real 
> distinction to be drawn between “horological” and “cultural”—no matter 
> what calendar rules might be used.


Looking for logic in dates/times/calendars is a recipe for a continuous 
pounding headache. Not the least because horological = cultural.

-- 
Adrian Klaver
adrian.klaver@aklaver.com





view thread (10+ messages)  latest in thread

Message-ID: <e8e1d2e4-1eca-d1c1-eaee-2081d1e40b56@aklaver.com>
Permalink:  ../e8e1d2e4-1eca-d1c1-eaee-2081d1e40b56@aklaver.com/
Also on:    postgresql.org/message-id/e8e1d2e4-1eca-d1c1-eaee-2081d1e40b56@aklaver.com

 · 

reply

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, tgl@sss.pgh.pa.us, folarte@peoplecall.com
  Subject: Re: = t1 - t0 but t0 + i <> t1 when t1 and t2 timestamptz values and i is an interval value
  In-Reply-To: <e8e1d2e4-1eca-d1c1-eaee-2081d1e40b56@aklaver.com>
  References: <402F8EFB-3FE9-421A-B3BA-F736AB8E3ABB@yugabyte.com> <1578541.1616765766@sss.pgh.pa.us> <DAABCBE6-6DFF-4C28-9CED-0AA8053FE12C@yugabyte.com> <e8e1d2e4-1eca-d1c1-eaee-2081d1e40b56@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