-
Notifications
You must be signed in to change notification settings - Fork 179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add additional lubridate translations for PostgreSQL #333
Comments
Hello @bkkkk, how are you using month grouping in dbplyr+pg provided there's still no support for that? |
@cassiopagnoncelli We use raw SQL. We go for one of the following:
query <- "SELECT
date_trunc('month', created_at) :: DATE AS created_at,
count(*)
FROM table
GROUP BY 1"
tbl(conn, sql(query))
my_tbl %>%
mutate(created_month = sql("date_trunc('month', created_at)")) %>%
group_by(created_month) %>%
summarize(total_amount = sum(amount))
|
Brilliant, thanks for sharing. I'm wondering to which point |
You're right, that's the way to do now. In addition, flooring date to first moment in month shifts back to last month if timezone is relatively before to UTC so I had to |
@cassiopagnoncelli I've never tested this very thoroughly since I usually convert everything to just dates to avoid these kinds of issues. The timezone of the connection can also have an impact. I think the interaction between lubridate, dbplyr, and timezones is something that could use some love. |
We make extensive use of dbplyr and lubridate and it would be great to have functions like
lubridate::weeks
,lubridate::months
, etc... translated into'1 weeks' :: INTERVAL
to enable easy date mathfloor_date(date, 'month')
translated intoDATE_TRUNC('month', date)
These two sets of functions are used all the time all the time in our codebase and it's a shame to lose our ability to test with local tibbles because of calls to
sql
during a dplyr verb chain.Submitted PR here: #335
The text was updated successfully, but these errors were encountered: