Re: Intervals and ISO 8601 duration

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Ken Tanzer <ken(dot)tanzer(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Sebastien Flaesch <sebastien(dot)flaesch(at)4js(dot)com>, pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Intervals and ISO 8601 duration
Date: 2023-01-13 23:44:24
Message-ID: d66d3ff9-2e85-253f-4637-cc488954f760@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 1/13/23 15:32, Ken Tanzer wrote:
> On Fri, Jan 13, 2023 at 3:03 PM Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com
> <mailto:adrian(dot)klaver(at)aklaver(dot)com>> wrote:
>
>
> WITH inters AS (
>      SELECT
>          '1 day 2 hours'::interval AS i1,
>          '26 hours'::interval AS i2,
>          justify_interval('1 day 2 hours'::interval) AS ij1,
>          justify_interval('26 hours'::interval) AS ij2
> )
> SELECT
>      *,
>      to_char(justify_interval(i1),'HH24:MM:SS') AS i1_char,
>      to_char(justify_interval(i2),'HH24:MM:SS') AS i2_char,
>      i1=i2 AS "Equal?"
>
>        i1       |    i2    |      ij1       |      ij2       | i1_char
> | i2_char  | Equal?
> ----------------+----------+----------------+----------------+----------+----------+--------
>   1 day 02:00:00 | 26:00:00 | 1 day 02:00:00 | 1 day 02:00:00 |
> 02:00:00
> | 02:00:00 | t
>
>
> I'm not quite sure what this is meant to convey.  Maybe justify_hours
> and justify_days will return something that uniquely maps to the raw
> data, and maybe it doesn't (I can't figure that out!).  But then there's
> still no justify_seconds or something that would get at the raw
> microseconds being stored.
>
> And I could be wrong, but it seems like you were aiming towards making
> these two intervals the same.  I was trying to zero in on the
> opposite--what is it that makes them different (not identical), and how
> to access that information.  I was assuming that if they were not

This:

WITH inters AS (
SELECT
'1 day 2 hours'::interval AS i1,
'26 hours'::interval AS i2
)
SELECT
i1=i2 AS "Equal?"
FROM inters;

say the intervals are equal.

If I am following what you want is to_char(<interval>,'HH24:MM:SS') to
be equal, correct?

> identical, the internal representation in Months, Days and Microseconds
> must be different--maybe that assumption is not valid.  And maybe there
> is currently no way to get that raw representation.  If that's the case,
> so be it, although I might then put in a small plug for it as a feature
> request. :) (*)
>
> Cheers,
> Ken
>
> (*) These are probably bad suggestions, but something like...
>
>      EXTRACT ( (RAWHOURS|RAWDAYS|RAWMICROSECONDS) ... ?
>      Or a function RAWEXTRACT( HOURS|DAYS|MICROSECONDS ) ?
>
>
> --
> Adrian Klaver
> adrian(dot)klaver(at)aklaver(dot)com <mailto:adrian(dot)klaver(at)aklaver(dot)com>
>
>
>
> --
> 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(dot)tanzer(at)agency-software(dot)org <mailto:ken(dot)tanzer(at)agency-software(dot)org>
> (253) 245-3801
>
> Subscribe to the mailing list
> <mailto:agency-general-request(at)lists(dot)sourceforge(dot)net?body=subscribe> to
> learn more about AGENCY or
> follow the discussion.

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2023-01-13 23:57:13 Re: Intervals and ISO 8601 duration
Previous Message Ken Tanzer 2023-01-13 23:32:44 Re: Intervals and ISO 8601 duration