Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fVUGb-0008Mz-Bm for pgsql-docs@arkaria.postgresql.org; Wed, 20 Jun 2018 03:58:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fVUGZ-0003PZ-0k for pgsql-docs@arkaria.postgresql.org; Wed, 20 Jun 2018 03:58:43 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fVUGY-0003PQ-Nf for pgsql-docs@lists.postgresql.org; Wed, 20 Jun 2018 03:58:42 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fVUGV-0004nq-WB for pgsql-docs@lists.postgresql.org; Wed, 20 Jun 2018 03:58:41 +0000 Received: from bruce by momjian.us with local (Exim 4.84_2) (envelope-from ) id 1fVUGV-0006M9-8U; Tue, 19 Jun 2018 23:58:39 -0400 Date: Tue, 19 Jun 2018 23:58:39 -0400 From: Bruce Momjian To: vodevsh@gmail.com, pgsql-docs@lists.postgresql.org Subject: Re: DATE_PART('field', INTERVAL) not intuitive literal reading of interval Message-ID: <20180620035839.GA32746@momjian.us> References: <152698651482.26744.15456677499485530703@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <152698651482.26744.15456677499485530703@wrigleys.postgresql.org> User-Agent: Mutt/1.5.23 (2014-03-12) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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 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 +