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') %>%
collect()
... 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?
|
mssql_sql_if <- function(cond, if_true, if_false = NULL) { |
I'm running into an issue when using mutate and ifelse (or if) on a SQL Server backend. The following sample query:
... will give the following translation:
Which will return an error. The correct translation should be:
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?
dbplyr/R/db-odbc-mssql.R
Line 225 in 477480e