In a Databricks SQL query, I am creating a column to get the difference in Timestamps of successive rows. I use something like the following,
select
(Timestamp - (LAG(Timestamp, 1) OVER (partition by colA order by Timestamp))) tdiff,
*
from
the_table
But this gives me value of type interval day to second
like {"seconds": 180, "nano": 0, "negative": false, "zero": false, "units": ["SECONDS", "NANOS"]}
How can I get it converted to seconds. For this example, I should basically see 180.
Looks like in earlier runtimes (tested at least for 13.2) datediff supports the seconds unit.
https://docs.databricks.com/en/sql/language-manual/functions/datediff3.html
This just generates some random ids with multiple values and a fuzzed time to show the syntax.
Also shows equivalent extract from interval as originally posed.