Re: Argument 'week' not supported in date_trunc function with intervals

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: caetanosauer(at)gmail(dot)com, pgsql-docs(at)lists(dot)postgresql(dot)org
Subject: Re: Argument 'week' not supported in date_trunc function with intervals
Date: 2020-01-18 02:20:51
Message-ID: 20200118022051.GE14054@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

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 <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

Browse pgsql-docs by date

  From Date Subject
Next Message Bruce Momjian 2020-01-18 02:31:19 Re: References between initdb and pg_controldata
Previous Message Bruce Momjian 2020-01-17 23:22:46 Re: doc: Add anchors in create_table.sgml