https://github.com/stefanov-sm/pre-pg14-date_bin-function
Postgresql date_bin for versions prior to 14. Can be used for running interval aggregation in time series data scenarios.
https://github.com/stefanov-sm/pre-pg14-date_bin-function
postgresql sql
Last synced: about 1 month ago
JSON representation
Postgresql date_bin for versions prior to 14. Can be used for running interval aggregation in time series data scenarios.
- Host: GitHub
- URL: https://github.com/stefanov-sm/pre-pg14-date_bin-function
- Owner: stefanov-sm
- License: mit
- Created: 2021-08-31T17:24:49.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-06-23T13:32:24.000Z (almost 3 years ago)
- Last Synced: 2025-02-15T23:42:24.882Z (3 months ago)
- Topics: postgresql, sql
- Language: PLpgSQL
- Homepage:
- Size: 30.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Postgresql date_bin function for versions prior to PG14
#### Postgresql `date_trunc` by interval. Can be used for running interval aggregation in time series data scenarios.
```sql
function date_bin(trunc_period interval, ts timestamptz, base_ts timestamptz default 'epoch')
returns timestamptz;
```
#### Demo
```sql
select now(), date_bin(interval '10 seconds', now());
```
yields
2021-09-13 23:18:**27.256826**, 2021-09-13 23:18:**20.0**