Re: truncating timestamps on arbitrary intervals
От | David Fetter |
---|---|
Тема | Re: truncating timestamps on arbitrary intervals |
Дата | |
Msg-id | 20200226075108.GH13804@fetter.org обсуждение исходный текст |
Ответ на | truncating timestamps on arbitrary intervals (John Naylor <john.naylor@2ndquadrant.com>) |
Ответы |
Re: truncating timestamps on arbitrary intervals
|
Список | pgsql-hackers |
On Wed, Feb 26, 2020 at 10:50:19AM +0800, John Naylor wrote: > Hi, > > When analyzing time-series data, it's useful to be able to bin > timestamps into equally spaced ranges. date_trunc() is only able to > bin on a specified whole unit. Thanks for adding this very handy feature! > In the attached patch for the March > commitfest, I propose a new function date_trunc_interval(), which can > truncate to arbitrary intervals, e.g.: > > select date_trunc_interval('15 minutes', timestamp '2020-02-16 > 20:48:40'); date_trunc_interval > --------------------- > 2020-02-16 20:45:00 > (1 row) I believe the following should error out, but doesn't. # SELECT date_trunc_interval('1 year 1 ms', TIMESTAMP '2001-02-16 20:38:40'); date_trunc_interval ═════════════════════ 2001-01-01 00:00:00 (1 row) > With this addition, it might be possible to turn the existing > date_trunc() functions into wrappers. I haven't done that here because > it didn't seem practical at this point. For one, the existing > functions have special treatment for weeks, centuries, and millennia. I agree that turning it into a wrapper would be separate work. > Note: I've only written the implementation for the type timestamp > without timezone. Adding timezone support would be pretty simple, > but I wanted to get feedback on the basic idea first before making > it complete. I've also written tests and very basic documentation. Please find attached an update that I believe fixes the bug I found in a principled way. Best, David. -- David Fetter <david(at)fetter(dot)org> http://fetter.org/ Phone: +1 415 235 3778 Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate
Вложения
В списке pgsql-hackers по дате отправления: