As of this question, I know there is an open feature request to add month/year to the time_bucket function.
My question is, what is the best way to accomplish this now. This issue mentions date_trunc
Here are the two approaches:
timescaledb's time_bucket
SELECT time_bucket('1 week', timestamp) AS "one_week",
count(*) AS "count",
first(value, timestamp) AS "first",
last(value, timestamp) AS "last"
FROM "event" "event"
WHERE event."signalId" = $1
GROUP BY one_week
ORDER BY one_week DESC
postgres date_trunc
SELECT date_trunc('month', timestamp) AS "one_month",
count(*) AS "count",
first(value, timestamp) AS "first",
last(value, timestamp) AS "last"
FROM "event" "event"
WHERE event."signalId" = $1
GROUP BY one_month
ORDER BY one_month DESC
Both of those work as expected (though I have not done any performance testing).
I would like to acheive:
- (a) gapfill (like timescaledb time_bucket_gapfill, and
- (b) last value carried forward (locf)
What is the best way to achieve that?
Thanks!