When a in-database (PostgreSQL) dplyr::mutate
operation calculates the difference between two timestamps, a character vector is returned, each element of the form like:
> RPostgreSQL::dbGetQuery(db$con, 'select now() - current_date;')
?column?
1 09:23:48.880493
In this case it is HH:MM:SS.ssssss
. How do I get dplyr
to return this vector of time differences in seconds? That is, I would like to do the same thing as here, except have it as part of a mutate
statement.
Example dplyr
code would be:
tbl(db$con, 'tmp_table') %>%
mutate(time_diff = received_at - started_at) %>%
select(id, time_diff) %>%
collect(n = Inf)