Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T1kXd-0002Gb-3V for pgsql-bugs@postgresql.org; Wed, 15 Aug 2012 20:50:13 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T1kXZ-0001rB-VT for pgsql-bugs@postgresql.org; Wed, 15 Aug 2012 20:50:12 +0000 Received: from bruce by momjian.us with local (Exim 4.72) (envelope-from ) id 1T1kXY-0002bb-Fx; Wed, 15 Aug 2012 16:50:08 -0400 Date: Wed, 15 Aug 2012 16:50:08 -0400 From: Bruce Momjian To: Noah Hamerslough Cc: pgsql-bugs@postgresql.org Subject: Re: BUG #6178: date_trunc : interval units "week" not supported contradicts documentation Message-ID: <20120815205008.GO25473@momjian.us> References: <201108251905.p7PJ5YLe075723@wwwmaster.postgresql.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="veXX9dWIonWZEC6h" Content-Disposition: inline In-Reply-To: <201108251905.p7PJ5YLe075723@wwwmaster.postgresql.org> User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201208/110 X-Sequence-Number: 33834 --veXX9dWIonWZEC6h Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Aug 25, 2011 at 07:05:34PM +0000, Noah Hamerslough wrote: > > The following bug has been logged online: > > Bug reference: 6178 > Logged by: Noah Hamerslough > Email address: noah@pcc.com > PostgreSQL version: 8.4 > Operating system: Windows Vista > Description: date_trunc : interval units "week" not supported > contradicts documentation > Details: > > http://www.postgresql.org/docs/8.4/static/functions-datetime.html#FUNCTIONS- > DATETIME-TRUNC > > The documentation for date_trunc('field', source) lists 'week' in the as a > valid value for 'field' However, if the source is an interval, 'week' is not > supported. > > select date_trunc('week', '1 month 15 days'::interval); > > ERROR: interval units "week" not supported > SQL state: 0A000 > > Either 'week' should be supported or the documentation should be updated to > reflect that it is not. Turns out the reason we don't support this is because there are usually a fractional number of weeks in a month, so there is no good way to do this for intervals. I have applied the attached patch to PG 9.3 which will explain why this is not supported. I saw this as better than a documentation mention. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + It's impossible for everything to be true. + --veXX9dWIonWZEC6h Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="week.diff" diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c new file mode 100644 index 8593b6b..2adc178 *** a/src/backend/utils/adt/timestamp.c --- b/src/backend/utils/adt/timestamp.c *************** interval_trunc(PG_FUNCTION_ARGS) *** 3710,3719 **** break; default: ! ereport(ERROR, ! (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), ! errmsg("interval units \"%s\" not supported", ! lowunits))); } if (tm2interval(tm, fsec, result) != 0) --- 3710,3726 ---- break; default: ! if (val == DTK_WEEK) ! ereport(ERROR, ! (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), ! errmsg("interval units \"%s\" not supported " ! "because months usually have fractional weeks", ! lowunits))); ! else ! ereport(ERROR, ! (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), ! errmsg("interval units \"%s\" not supported", ! lowunits))); } if (tm2interval(tm, fsec, result) != 0) --veXX9dWIonWZEC6h--