truncating timestamps on arbitrary intervals
От | John Naylor |
---|---|
Тема | truncating timestamps on arbitrary intervals |
Дата | |
Msg-id | CACPNZCt4buQFRgy6DyjuZS-2aPDpccRkrJBmgUfwYc1KiaXYxg@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: truncating timestamps on arbitrary intervals
Re: truncating timestamps on arbitrary intervals |
Список | pgsql-hackers |
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. 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) 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. 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. -- John Naylor https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Вложения
В списке pgsql-hackers по дате отправления: