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
pmin and pmax fail in mutate connected to SQL Server #118
Comments
@edgararuiz commented on Dec 2, 2017, 3:31 AM UTC: You're correct, |
@DavisVaughan commented on Dec 23, 2017, 1:04 PM UTC: @edgararuiz, You guys could take the approach I used for Access. It only works for two columns, but that is the most common case. # pmin/pmax for 2 columns
pmin = function(x, y) {
sql_expr(iif(UQ(x) <= UQ(y), !!x, !!y))
},
pmax = function(x, y) {
sql_expr(iif(UQ(x) <= UQ(y), !!y, !!x))
}, |
@krlmlr commented on Jan 17, 2018, 9:14 AM UTC: @DavisVaughan: Macro expansion is a slippery slope, what if Out of curiosity: Which databases actually support pairwise |
@edgararuiz commented on Jan 17, 2018, 1:45 PM UTC: You're right, we would enable it only for those who support it. I believe can also do |
@DavisVaughan commented on Jan 17, 2018, 2:46 PM UTC: For completeness, Postgres and MySQL have Docs for Postgres at the bottom here Docs for MySQL here A stack overflow Q/A confirming the equivalence of Postgres |
@hadley commented on Jun 7, 2018, 11:43 PM UTC: Let's remove it from the default translation, and add to Postgres, MySQL, and SQLite. Is it worth making the default translation an error? |
@krlmlr commented on Jun 18, 2018, 8:46 AM UTC: If we don't translate |
For reference, Oracle also uses LEAST and GREATEST. |
LEAST and GREATEST in PostgreSQL (and perhaps also MySQL and Oracle) may not provide the same implementation as pmin and pmax in R in the presence of NA values. See for instance the example below
The same result with LEAST and GREATEST from PostgreSQL gives
|
We should probably make |
|
@jnolis commented on Nov 28, 2017, 6:36 PM UTC:
Occasionally, I will need to use pmin or pmax to replace values above or below a threshold, for instance:
However, when I use dbplyr to try and do this using a SQL Server table, I get the following error:
As you can see, the SQL code generator assumes that I want to do a pairwise MAX, however SQL Server does not support that (only taking the maximum over a single column).
A cursory Stack Overflow search suggests that to do this operation a case statement could be used. I think either the SQL code generator should either be updated to do this, or an error should be generated at the time of calling the mutate.
This issue was moved by krlmlr from tidyverse/dplyr/issues/3227.
The text was updated successfully, but these errors were encountered: