pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #6178: date_trunc : interval units "week" not supported contradicts documentation
2+ messages / 2 participants
[nested] [flat]
* BUG #6178: date_trunc : interval units "week" not supported contradicts documentation
@ 2011-08-25 19:05 Noah Hamerslough <noah@pcc.com>
0 siblings, 1 reply; 2+ messages in thread
From: Noah Hamerslough @ 2011-08-25 19:05 UTC (permalink / raw)
To: pgsql-bugs
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.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #6178: date_trunc : interval units "week" not supported contradicts documentation
@ 2012-08-15 20:50 Bruce Momjian <bruce@momjian.us>
parent: Noah Hamerslough <noah@pcc.com>
0 siblings, 0 replies; 2+ messages in thread
From: Bruce Momjian @ 2012-08-15 20:50 UTC (permalink / raw)
To: Noah Hamerslough <noah@pcc.com>; +Cc: pgsql-bugs
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 <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ It's impossible for everything to be true. +
Attachments:
week.diff (text/x-diff, 1.0K) download
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)
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2012-08-15 20:50 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-08-25 19:05 BUG #6178: date_trunc : interval units "week" not supported contradicts documentation Noah Hamerslough <noah@pcc.com>
2012-08-15 20:50 ` Bruce Momjian <bruce@momjian.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox