pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Ken Tanzer <ken.tanzer@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Sebastien Flaesch <sebastien.flaesch@4js.com>
Cc: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: Re: Intervals and ISO 8601 duration
Date: Fri, 13 Jan 2023 21:27:15 -0800
Message-ID: <dda7b10f-9738-4593-d392-4d6df44af1f9@aklaver.com> (raw)
In-Reply-To: <CAD3a31V2_qf_KS6cC2yPehR9mB+V+9h354gSpzQ2ioeDk5Zj_w@mail.gmail.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>
	<13f80fd5-6baf-e272-54c7-e72e32280643@aklaver.com>
	<CAD3a31XM7TczB9aY2AA3Ld7PFLuwLra3dxqPu2zGd5F0Kb9w2Q@mail.gmail.com>
	<d66d3ff9-2e85-253f-4637-cc488954f760@aklaver.com>
	<CAD3a31Vk7z_ADWt8qtySB+An8aFTGmYvT5979Da0JGhDoy3yUg@mail.gmail.com>
	<892688.1673657835@sss.pgh.pa.us>
	<CAD3a31V2_qf_KS6cC2yPehR9mB+V+9h354gSpzQ2ioeDk5Zj_w@mail.gmail.com>

On 1/13/23 17:24, Ken Tanzer wrote:
> On Fri, Jan 13, 2023 at 4:57 PM Tom Lane <tgl@sss.pgh.pa.us 
> <mailto:tgl@sss.pgh.pa.us>> wrote:
> 
> 
>     Given what extract() provides,
> 
>     stored months = years * 12 + months
> 
>     stored days = days
> 
>     stored usec = reconstruct from hours+minutes+seconds+microseconds
> 
>     Perhaps it wouldn't be a bad idea to provide a couple more extract()
>     keywords to make that easier.
> 
> 
> Thanks Tom!  That helped me spell it out and understand it a little more 
> clearly.  Both to understand the non-identicalness, and to see the 
> specifics.  But yeah it would be nice if it was a little easier to 
> extract! :)
> 
> WITH foo AS (
> WITH inters AS (
>       SELECT
>           '1 day 2 hours'::interval AS i1,
>           '26 hours'::interval AS i2
> )
> SELECT
>       *,
>      EXTRACT(YEARS FROM i1)*12 + EXTRACT(MONTHS FROM i1) AS i1_months,
>      EXTRACT(DAYS FROM i1) AS i1_days,
>      EXTRACT(HOURS FROM i1) * 60 * 60 * 1000
>          + EXTRACT(MINUTES FROM i1) * 60 * 1000
>          + EXTRACT(SECONDS FROM i1) * 1000
>          + EXTRACT(MICROSECONDS FROM i1)
>      AS i1_msec,
>      EXTRACT(YEARS FROM i2)*12 + EXTRACT(MONTHS FROM i2) AS i2_months,
>      EXTRACT(DAYS FROM i2) AS i2_days,
>      EXTRACT(HOURS FROM i2) * 60 * 60 * 1000
>          + EXTRACT(MINUTES FROM i2) * 60 * 1000
>          + EXTRACT(SECONDS FROM i2) * 1000
>          + EXTRACT(MICROSECONDS FROM i2)
>      AS i2_msec,
>      i1=i2 AS equals
> FROM inters
> )
> SELECT
>      *,
>      (i1_months=i2_months AND i1_days=i2_days AND i1_msec=i2_msec) AS 
> identical,
>      i1_months * 30 * 24 * 60 * 60 * 1000
>          + i1_days * 24 * 60 * 60 * 1000
>          + i1_msec AS i1_msec_total,
>      i2_months * 30 * 24 * 60 * 60 * 1000
>          + i2_days * 24 * 60 * 60 * 1000
>          + i2_msec AS i2_msec_total
> 
> FROM foo;
> 
> -[ RECORD 1 ]-+---------------
> i1            | 1 day 02:00:00
> i2            | 26:00:00
> i1_months     | 0
> i1_days       | 1
> i1_msec       | 7200000
> i2_months     | 0
> i2_days       | 0
> i2_msec       | 93600000
> equals        | t
> identical     | f
> i1_msec_total | 93600000
> i2_msec_total | 93600000

I don't see how the above answers, from your previous post, the below:

1) Is the internal representation in months, days and microseconds 
different for these two intervals?
2) (If no, what else is it that makes them non-identical?)
3)  Is there a way to access the internal representation?

What you have done is reformat the intervals and establish that the 
formatted values point back at equal and most probably identical values.

> 
> Cheers,
> Ken
> -- 
> AGENCY Software
> A Free Software data system
> By and for non-profits
> /http://agency-software.org/ <http://agency-software.org/>/
> /https://demo.agency-software.org/client 
> <https://demo.agency-software.org/client>/
> ken.tanzer@agency-software.org <mailto:ken.tanzer@agency-software.org>
> (253) 245-3801
> 
> Subscribe to the mailing list 
> <mailto:agency-general-request@lists.sourceforge.net?body=subscribe> to
> learn more about AGENCY or
> follow the discussion.

-- 
Adrian Klaver
adrian.klaver@aklaver.com






view thread (24+ messages)  latest in thread

Message-ID: <dda7b10f-9738-4593-d392-4d6df44af1f9@aklaver.com>
Permalink:  ../dda7b10f-9738-4593-d392-4d6df44af1f9@aklaver.com/
Also on:    postgresql.org/message-id/dda7b10f-9738-4593-d392-4d6df44af1f9@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, ken.tanzer@gmail.com, tgl@sss.pgh.pa.us, sebastien.flaesch@4js.com
  Subject: Re: Intervals and ISO 8601 duration
  In-Reply-To: <dda7b10f-9738-4593-d392-4d6df44af1f9@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> <13f80fd5-6baf-e272-54c7-e72e32280643@aklaver.com> <CAD3a31XM7TczB9aY2AA3Ld7PFLuwLra3dxqPu2zGd5F0Kb9w2Q@mail.gmail.com> <d66d3ff9-2e85-253f-4637-cc488954f760@aklaver.com> <CAD3a31Vk7z_ADWt8qtySB+An8aFTGmYvT5979Da0JGhDoy3yUg@mail.gmail.com> <892688.1673657835@sss.pgh.pa.us> <CAD3a31V2_qf_KS6cC2yPehR9mB+V+9h354gSpzQ2ioeDk5Zj_w@mail.gmail.com> <dda7b10f-9738-4593-d392-4d6df44af1f9@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