Re: DATE_PART('field', INTERVAL) not intuitive literal reading of interval

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: vodevsh(at)gmail(dot)com, pgsql-docs(at)lists(dot)postgresql(dot)org
Subject: Re: DATE_PART('field', INTERVAL) not intuitive literal reading of interval
Date: 2018-06-20 03:58:39
Message-ID: 20180620035839.GA32746@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

On Tue, May 22, 2018 at 10:55:14AM +0000, PG Doc comments form wrote:
> The following documentation comment has been logged on the website:
>
> Page: https://www.postgresql.org/docs/10/static/functions-datetime.html
> Description:
>
> the result of
> t=# SELECT DATE_PART('month', '2018-05-31'::timestamp -
> '2018-02-24'::timestamp);
> date_part
> -----------
> 0
> (1 row)
>
> looks correct, but not intuitive, maybe we need a NB for:
>
> t=# SELECT DATE_PART('month', justify_interval('2018-05-31'::timestamp -
> '2018-02-24'::timestamp));
> date_part
> -----------
> 3
> (1 row)
>
> https://stackoverflow.com/questions/50465632/postgresql-10-4-date-difference/50465676#50465676

This is really a function of how interval computes months, days, and
seconds from subtraction, which is outlined here:

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

I don't think adding something to the functions-datetime.html section
makes sense. For example, this returns 1:

SELECT extract(minutes from '1 hour 1 minute'::interval);
date_part
-----------
1

(Uh, it is kind of odd for EXTRACT to return a date_part column label.)
The point is that the subtraction doesn't justify the values.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ As you are, so once was I. As I am, so you will be. +
+ Ancient Roman grave inscription +

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Bruce Momjian 2018-06-20 12:12:17 Re: DATE_PART('field', INTERVAL) not intuitive literal reading of interval
Previous Message Euler Taveira 2018-06-20 02:20:44 Re: postgresql 11 release notes