Skip to content
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

dbplyr translation of pmax/pmin throws an error if it receives the na.rm = TRUE argument #479

Closed
fh-jgutman opened this issue Jun 12, 2020 · 0 comments
Labels
feature a feature request or enhancement func trans 🌍 Translation of individual functions to SQL

Comments

@fh-jgutman
Copy link

With aggregate functions like max and min, the dbplyr:::check_na_rm gives a useful warning if the na.rm = TRUE option is not provided, and if na.rm = TRUE is provided, the option gets silently ignored. This behavior does not exist for the non-aggregate functions pmax() and pmin, which are now translated to GREATEST and LEAST in certain db backends. Instead, providing the option pmax(..., na.rm = TRUE) currently throws an error.

The desired behavior is that, similar to aggregate functions min/max, pmin and pmax also throw a warning via dbplyr:::check_na_rm if no na.rm argument is provided, and that no error is thrown if na.rm = TRUE is provided.

pg_con <- DBI::dbConnect(RPostgres::Postgres(), "test_data")
dplyr::copy_to(pg_con, mtcars)
db_mtcars <- dplyr::tbl(pg_con, "mtcars")

db_mtcars %>%
   dplyr::summarise(max_mpg = max(mpg, na.rm = TRUE)) # desired behavior

db_mtcars %>%
   dplyr::mutate(new_size = pmax(wt, drat, na.rm = TRUE)) # throws error

Output:

Error: Failed to prepare query: ERROR:  syntax error at or near "AS"
LINE 1: ..."am", "gear", "carb", GREATEST("wt", "drat", TRUE AS "na.rm"...
                                                             ^
In addition: Warning message:
Named arguments ignored for SQL GREATEST 
@hadley hadley added feature a feature request or enhancement func trans 🌍 Translation of individual functions to SQL labels Sep 17, 2020
@hadley hadley closed this as completed in a4cb725 Sep 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement func trans 🌍 Translation of individual functions to SQL
Projects
None yet
Development

No branches or pull requests

2 participants