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

MS SQL needs to translate FALSE & TRUE in two ways #377

Closed
robchallen opened this issue Nov 28, 2019 · 2 comments
Closed

MS SQL needs to translate FALSE & TRUE in two ways #377

robchallen opened this issue Nov 28, 2019 · 2 comments
Labels
bug an unexpected problem or unintended behavior func trans 🌍 Translation of individual functions to SQL

Comments

@robchallen
Copy link

Creating a new variable in a MSSQL dbplyr backed table that involves a logical value in R generates an SQL error as R TRUE gets converted to MSSQL TRUE which doesn't exist in the context of a select statement (...why? I don't know)

Workaround is not to use TRUE in R and use as.logical(1) instead.

library(dbplyr)
library(DBI)

#assume a DBI connection con

tmp = data.frame(test=c(1))
con %>% copy_to(tmp) 

# Created a temporary table named: ##tmp
tmp %>% mutate(test2 = TRUE) 

# Error: <SQL> 'SELECT TOP(11) "test", TRUE AS "test2" FROM "##tmp"'   nanodbc/nanodbc.cpp:1587: 42S22: [Microsoft][ODBC Driver 13 for SQL Serve
--

# workaround
tmp %>% mutate(test2 = as.logical(1))
@robchallen
Copy link
Author

[#250] was a similar issue

@hadley hadley added bug an unexpected problem or unintended behavior func trans 🌍 Translation of individual functions to SQL labels Dec 13, 2019
@hadley
Copy link
Member

hadley commented Dec 13, 2019

We need to generate different translations of T/F depending what clause we're currently in. We've probably forgotten to pass apply this detail when escaping a literal TRUE or FALSE

@hadley hadley changed the title MSSQL mutate using R TRUE/FALSE MS SQL needs to translate FALSE & TRUE in two ways Sep 17, 2020
hadley added a commit that referenced this issue Sep 22, 2020
@hadley hadley closed this as completed in 3b1767d Sep 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior func trans 🌍 Translation of individual functions to SQL
Projects
None yet
Development

No branches or pull requests

2 participants