Re: truncating timestamps on arbitrary intervals

From: Justin Pryzby <pryzby(at)telsasoft(dot)com>
To: Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>
Cc: John Naylor <john(dot)naylor(at)enterprisedb(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: truncating timestamps on arbitrary intervals
Date: 2021-04-22 09:16:04
Message-ID: 20210422091604.GB7256@telsasoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Apr 09, 2021 at 10:02:47PM +0200, Peter Eisentraut wrote:
> On 30.03.21 18:50, John Naylor wrote:
> > On Sat, Mar 27, 2021 at 1:06 PM Justin Pryzby wrote:
> > >
> > > The current docs seem to be missing a "synopsis", like
> > >
> > > +<synopsis>
> > > +date_trunc(<replaceable>stride</replaceable>, <replaceable>timestamp</replaceable>, <replaceable>origin</replaceable>)
> > > +</synopsis>
> >
> > The attached
> > - adds a synopsis
> > - adds a bit more description to the parameters similar to those in
> > date_trunc
> > - documents that negative intervals are treated the same as positive ones
> >
> > Note on the last point: This just falls out of the math, so was not
> > deliberate, but it seems fine to me. We could ban negative intervals,
> > but that would possibly just inconvenience some people unnecessarily. We
> > could also treat negative strides differently somehow, but I don't
> > immediately see a useful and/or intuitive change in behavior to come of
> > that.
>
> committed

It looks like we all missed that I misspelled "date_bin" as
"date_trunc"...sorry. I will include this with my next round of doc review, in
case you don't want to make a separate commit for it.

https://www.postgresql.org/docs/devel/functions-datetime.html#FUNCTIONS-DATETIME-BIN

From f4eab5c0f908d868540ab33aa12b82fd05f19f52 Mon Sep 17 00:00:00 2001
From: Justin Pryzby <pryzbyj(at)telsasoft(dot)com>
Date: Thu, 22 Apr 2021 03:37:18 -0500
Subject: [PATCH] date_bin: fixup for added documentation in 49fb4e

---
doc/src/sgml/func.sgml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index 53f4c09c81..cc4e1b0a36 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -9946,13 +9946,13 @@ date_trunc(<replaceable>stride</replaceable>, <replaceable>timestamp</replaceabl

<para>
<synopsis>
-date_trunc(<replaceable>stride</replaceable>, <replaceable>source</replaceable>, <replaceable>origin</replaceable>)
+date_bin(<replaceable>stride</replaceable>, <replaceable>source</replaceable>, <replaceable>origin</replaceable>)
</synopsis>
<replaceable>source</replaceable> is a value expression of type
<type>timestamp</type> or <type>timestamp with time zone</type>. (Values
of type <type>date</type> are cast automatically to
<type>timestamp</type>.) <replaceable>stride</replaceable> is a value
- expression of type <type> interval</type>. The return value is likewise
+ expression of type <type>interval</type>. The return value is likewise
of type <type>timestamp</type> or <type>timestamp with time zone</type>,
and it marks the beginning of the bin into which the
<replaceable>source</replaceable> is placed.
--
2.17.0

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Julien Rouhaud 2021-04-22 09:23:18 Re: Feature improvement: can we add queryId for pg_catalog.pg_stat_activity view?
Previous Message houzj.fnst@fujitsu.com 2021-04-22 09:08:49 RE: [bug?] Missed parallel safety checks, and wrong parallel safety