Re: truncating timestamps on arbitrary intervals

From: John Naylor <john(dot)naylor(at)enterprisedb(dot)com>
To: Bauyrzhan Sakhariyev <baurzhansahariev(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: truncating timestamps on arbitrary intervals
Date: 2021-07-22 17:28:38
Message-ID: CAFBsxsE1D8buF1xeGFi6FYghxEhnoBGHAngDE52KK-8O2KOd4g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Jul 22, 2021 at 12:24 PM Bauyrzhan Sakhariyev <
baurzhansahariev(at)gmail(dot)com> wrote:
>
> Is date_bin supposed to return the beginning of the bin?

Thanks for testing! And yes.

> And does the sign of an interval define the "direction" of the bin?

No, the boundary is intentionally the earlier one:

/*
* Make sure the returned timestamp is at the start of the bin, even if
* the origin is in the future.
*/
if (origin > timestamp && stride_usecs > 1)
tm_delta -= stride_usecs;

I wonder if we should just disallow negative intervals here.

--
John Naylor
EDB: http://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Mark Dilger 2021-07-22 17:29:13 Re: Delegating superuser tasks to new security roles (Was: Granting control of SUSET gucs to non-superusers)
Previous Message Arne Roland 2021-07-22 17:22:57 Re: Rename of triggers for partitioned tables