You can use the first_value() window function to get the timestamp from the row before partitioned by Sym. At the moment we need a workaround, as the timestamp data type is not supported for this window function, but please do vote the github issue to raise awareness
You could do this to check gaps in all the rows for today. I am displaying the gap in both seconds and millis for completeness. Then you could add a condition to show only those above a certain threshold.
WITH time_and_prev AS (
SELECT Datetime, Sym, first_value(Datetime::long) OVER (PARTITION BY Sym ORDER BY Datetime ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING ) AS prevTimestamp
FROM table where timestamp IN today()
)
SELECT Datetime, Sym, prevTimestamp::timestamp, datediff('s', Datetime, prevTimestamp::timestamp) as gap_s, (Datetime - prevTimestamp::timestamp) / 1000 as gap_ms FROM time_and_prev ;
Thanks Javier so much for the quick & thorough response!
For this section of your query (I forgot to specify my table’s name, so your query has it as ‘table’) :
FROM table where timestamp IN today()
I assume you meant:
FROM table where Datetime IN today()
Unfortunately this gives an error: “unknown function name: today()”.
I’m not clear why today() didn’t work, but I just replaced the today() call with a str constant (eg: ‘2024’).
You are correct, sorry I messed up the column names!
The today() function was recently added. It might be the case you are running an older version of questdb. In any case, the important part is on the window function, for the where filter you can just use anything you might need.