Skip to content

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

Description

@robchallen

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))

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorfunc trans 🌍Translation of individual functions to SQL

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions