We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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?
to your account
I'm running into an issue when using mutate and ifelse (or if) on a SQL Server backend. The following sample query:
df <- tbl(con, in_schema("schema", "table_name")) %>%
mutate(field = ifelse(field %in% c('test1', 'test2', 'test3'), 'string1', 'string2') %>%
... will give the following translation:
SELECT CASE WHEN (("field" IN ('test1', 'test2', 'test3')) = 'TRUE') THEN ('string1')
WHEN (("field" IN ('test1', 'test2', 'test3')) = 'FALSE') THEN ('string2')
END AS "field"
Which will return an error. The correct translation should be:
SELECT CASE WHEN ("field" IN ('test1', 'test2', 'test3')) THEN 'string1'
WHEN ("field" NOT IN ('test1', 'test2', 'test3')) THEN 'string2'
END AS "field"
Will correcting this in the mssql_if function create any issues in other queries, or is there a better way to do mutate(ifelse()) in mssql?
The text was updated successfully, but these errors were encountered:
Sorry guys. Just opened up a ticket in dplyr instead (as suggested in the readme). Closing this guy. Opened tidyverse/dplyr#3632
Sorry, something went wrong.
No you should file here; I need to update the readme.
Thanks Hadley. @edgararuiz, any insight on what a fix might be?
Ok, I think that the update may have to be done in the negating function here:
I'll work on a PR for this
Quick update, it looks like your suggestion fixes this issue, but it negatively impacts the custom MS SQL infix function we're using, so I have to work some more on this
Thanks for your help on this @edgararuiz! We're transitioning from a MySQL db to MSSQL and it's been super smooth thus far minus this kink.
Did this issue get worked out or is there a workaround? I'm having the same problem.
@ablack3 - Yes, I have a PR that fixes it. The PR is ready to be reviewed: #103
Improve ifelse() translation for MS SQL (#103)
Fixes #165. Fixes #93
Successfully merging a pull request may close this issue.