Hey, let me lay out my scenario.
I have a bunch of data, each row is around 1-2 seconds apart and there is approx 10 million rows of data.
Each rows has an account_id and value.
For each account
I want to be able to group the data into 30 minute time buckets and select the latest value in each bucket. I only need the data for the past x days (in the example below, 90 days) I am having a lot of trouble creating an efficient query to do this.
Here is an example
SELECT
last(account_id, timestamp),
last(timestamp, timestamp),
last(value, timestamp),
last(c, timestamp),
last(d, timestamp),
last(e, timestamp),
last(f, timestamp),
last(g, timestamp),
time_bucket('0.5 hour', timestamp) AS bucket
FROM table
WHERE account_id = '?'
AND timestamp >= date_trunc('day', CURRENT_TIMESTAMP - interval '90 day')
GROUP BY bucket
ORDER BY bucket
Ideally, i want to have something like but i am not sure how.
select last(*, timestamp)
This query also doesnt seem very efficient, and takes up to 30 seconds to run.
If i just do a simple order by timestamp query, and then do the ‘bucketing’ in the application java code it runs much faster. Wondering if i am misusing timescale here.