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

filter() on boolean/legal variables only works with 1 and 0 #1116

Open
DaZaM82 opened this issue Jan 31, 2023 · 4 comments
Open

filter() on boolean/legal variables only works with 1 and 0 #1116

DaZaM82 opened this issue Jan 31, 2023 · 4 comments
Labels

Comments

@DaZaM82
Copy link

DaZaM82 commented Jan 31, 2023

I have a table with a boolean/legal column. I used filter(my_lgl_column == TRUE) and this throws an error as follows:
Error: nanodbc/nanodbc.cpp:1655: 42000: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid column name 'TRUE'. [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Statement(s) could not be prepared.

I found that changing the filter to 1's and 0's corrects this issue: filter(my_lgl_column == 1)

Although both would work with a local dataframe as well, would be good if dbplyr could convert TRUE/FALSE to 1/0 in the query script.

I'm working with SQL Server and odbc connection.

conn <- dbConnect(
  odbc::odbc(),
  driver = "ODBC Driver 17 for SQL Server",
  database = "NAME", # dummy name
  server = "servernane.net", # dummy server
  Trusted_Connection = "yes"
)
df <- data.frame(col = c(TRUE, FALSE, TRUE, FALSE))
df_sql <- dbWriteTable(conn, "test", df, overwrite = TRUE)

df_sql %>% filter(col == TRUE) #fails
df_sql %>% filter(col == 1) #success
@mgirlich
Copy link
Collaborator

mgirlich commented Feb 2, 2023

What's the class of your connection?

@DaZaM82
Copy link
Author

DaZaM82 commented Feb 2, 2023

What's the class of your connection?

I believe it is S4 object of class Microsoft SQL Server
I'm not an expert on this so if that's not the answer you are looking for then please let me know how to determine it in RStudio desktop.

@mgirlich mgirlich added the MSSQL label Apr 26, 2023
@hadley
Copy link
Member

hadley commented Dec 19, 2023

Have you tried df_sql %>% filter(col)?

@hadley
Copy link
Member

hadley commented Dec 21, 2023

Fixed by #1288

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants