Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1isdjS-0000Wo-KW for pgsql-docs@arkaria.postgresql.org; Sat, 18 Jan 2020 02:21:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1isdjQ-0001tU-K4 for pgsql-docs@arkaria.postgresql.org; Sat, 18 Jan 2020 02:21:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1isdjQ-0001tN-CP for pgsql-docs@lists.postgresql.org; Sat, 18 Jan 2020 02:21:00 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1isdjI-0004p0-Vd for pgsql-docs@lists.postgresql.org; Sat, 18 Jan 2020 02:20:59 +0000 Received: from bruce by momjian.us with local (Exim 4.92) (envelope-from ) id 1isdjH-0007Pk-Hh; Fri, 17 Jan 2020 21:20:51 -0500 Date: Fri, 17 Jan 2020 21:20:51 -0500 From: Bruce Momjian To: caetanosauer@gmail.com, pgsql-docs@lists.postgresql.org Subject: Re: Argument 'week' not supported in date_trunc function with intervals Message-ID: <20200118022051.GE14054@momjian.us> References: <157805468778.1149.10815835689820301977@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <157805468778.1149.10815835689820301977@wrigleys.postgresql.org> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, Jan 3, 2020 at 12:31:27PM +0000, PG Doc comments form wrote: > The following documentation comment has been logged on the website: > > Page: https://www.postgresql.org/docs/12/functions-datetime.html > Description: > > In the documentation of the date_trunc function (9.9.2), the first argument > (field) cannot be 'week' if the second argument (source) is an interval: > > csauer=# SELECT DATE_TRUNC('week', INTERVAL '7 days'); > > > > ERROR: interval units "week" not supported because months usually have > fractional weeks > csauer=# SELECT DATE_TRUNC('week', INTERVAL '1 week'); > > > > ERROR: interval units "week" not supported because months usually have > fractional weeks > > The documentation should state that explicitly. > > I also think the error message could be improved, because in the cases above > there are no months involved and the result should be 1. Uh, we could modify the code so that we allow SELECT DATE_TRUNC('week', INTERVAL '') to work if there is no month component, since interval is made up of months, days, and time. However, this would mean the function would work with some interval values, and not others. Is that an improvement? -- 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 +