Just getting started with timescaledb. I have a sensor data log that has a “session_id” to group experiments. I’d like to run a query that finds the start and end of the “session” experiment, then provides a continuous time output of count,min,max of samples, etc.
I hoped that putting the start and stop times into a subquery would work for time_bucket_gapfill(),
ERROR: invalid time_bucket_gapfill argument: start must be a simple expression
Is there any way around this limitation in SQL without using a procedural language?
SELECT
time_bucket_gapfill('1 hour', ts,session_start,session_end) AS ts_hour,
count(ts) AS count
FROM rawdata ,
(
select session_id as max_session, min(ts) as session_start, max(ts) as session_end from rawdata where
session_id=(select max(session_id) from sessions)
GROUP BY SESSION_ID
) as this_session
where session_id=this_session.max_session
-- Also does not work
--and ts>this_session.session_start and ts<=this_session.session_end and
group by ts_hour