Re: Intervals and ISO 8601 duration - Mailing list pgsql-general

From Ken Tanzer
Subject Re: Intervals and ISO 8601 duration
Date
Msg-id CAD3a31UHFVx_GMaf6zC1oVzJJjafchmHcKLO5UU=s3jhGa-+PQ@mail.gmail.com
Whole thread Raw
In response to Intervals and ISO 8601 duration  (Sebastien Flaesch <sebastien.flaesch@4js.com>)
List pgsql-general
(resending--Martin didn't realize you hadn't sent to the list too.)

On Fri, Jan 13, 2023 at 2:28 PM Martin L. Buchanan <martinlbuchanan@gmail.com> wrote:
Dear Ken:

You can extract individual subfields of interval as described here:



Hi Martin.  I don't think that really gets at what's actually being stored.  For example, look at a 2-year interval.  Tom says they are being represented internally as Months, Days and Microseconds.  But if you use extract it does not report anything for these values, because for example months which might be 24 internally is being reported as 0 because years is reported as 2:

SELECT EXTRACT(YEARS FROM '2 years'::interval) AS years, EXTRACT(MONTHS FROM '2 years'::interval) AS months,  EXTRACT(DAYS FROM '2 years'::interval) AS days, EXTRACT(MICROSECONDS FROM '2 years'::interval) AS seconds;

 years | months | days | seconds
-------+--------+------+---------
     2 |      0 |    0 |       0


(1 row)


--
AGENCY Software  
A Free Software data system
By and for non-profits
(253) 245-3801

learn more about AGENCY or
follow the discussion.


--
AGENCY Software  
A Free Software data system
By and for non-profits
(253) 245-3801

learn more about AGENCY or
follow the discussion.

pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Intervals and ISO 8601 duration
Next
From: "David G. Johnston"
Date:
Subject: Re: Intervals and ISO 8601 duration