I've have a Postgres database and I'm using Grafana to visualise some data.
For instance, my Grafana panel has the following variables where the values are dynamic:
- $__timeFrom() = '2023-10-21T00:00:00Z'
- $__timeTo() = '2023-10-21T00:25:00Z'
- $__interval = '15m'
These variables are used to generate a time series table, where the time is generated like this:
SELECT *
FROM generate_series('2023-10-21T00:00:00Z'::timestamp, '2023-10-21T00:25:00Z'::timestamp, '15m')
ORDER BY 1;
The above query gives me the following slots:
- 2023-10-21 00:00:00.000000
- 2023-10-21 00:15:00.000000
But I would like it to round up and generate a slot for the remaining time, by having a third slot with either the end date or the next value in the interval:
- 2023-10-21 00:00:00.000000
- 2023-10-21 00:15:00.000000
- 2023-10-21 00:25:00.000000 / 2023-10-21 00:30:00.000000
How can I solve this?
that depends what result you need
fiddle