I have a table which has the following columns:
id, start_timestamp, device_id
I am trying to get results of all start_timestamps within 5 seconds of a range of generated periodic timestamps.
For example, generating a series of timestamps every 80 seconds, I need to get all 'start_timestamps' that fall within 5 seconds of each of those timestamps.
So something like this query, but can't figure out the actual query. CTEs might be too exhaustive as the table has millions of records.
Appreciate any help, thanks!
SELECT *
FROM time_intersections
WHERE start_timestamp **within 5 seconds of each of these:**
(
SELECT *
FROM generate_series(timestamp '2021-03-07',
timestamp '2021-08-16',
interval '80 sec')
)
date_bin
from PostgreSQL v14 will make that simple.