Skip to content

glue_sql : quote integer if NA in the column #130

@philibe

Description

@philibe

It's a little the next of #115 : When I have an Integer with NA in same column, I get the integer with quote.

However it's casted by my SGBDR.
When I replace .con = DBI::ANSI() by my SQL Server connection I have the same bug.

library(glue)

glue_sql(
  "{Col_int}",
  Col_int = data.frame(
    Col_int = c(1L, NA_integer_),
    stringsAsFactors = FALSE
  )$Col_int,
  .con = DBI::ANSI()
)
#> <SQL> '1'
#> <SQL> NULL


glue_sql(
  "{Col_int}",
  Col_int = as.numeric(data.frame(
    Col_int = c(1L, NA_integer_),
    stringsAsFactors = FALSE
  )$Col_int),
  .con = DBI::ANSI()
)
#> <SQL> '1'
#> <SQL> NULL

glue_sql(
  "{Col_int}",
  Col_int = as.numeric(data.frame(
    Col_int = c(1, 2),
    stringsAsFactors = FALSE
  )$Col_int),
  .con = DBI::ANSI()
)
#> <SQL> 1
#> <SQL> 2
sessionInfo() with glue 1.31

#> R version 3.4.4 (2018-03-15)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 16.04.4 LTS
#> 
#> Matrix products: default
#> BLAS: /usr/lib/libblas/libblas.so.3.6.0
#> LAPACK: /usr/lib/lapack/liblapack.so.3.6.0
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
#>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] glue_1.3.1
#> 
#> loaded via a namespace (and not attached):
#>  [1] compiler_3.4.4  backports_1.1.2 magrittr_1.5    rprojroot_1.3-2
#>  [5] DBI_1.0.0       tools_3.4.4     htmltools_0.3.6 yaml_2.2.0     
#>  [9] Rcpp_1.0.0      stringi_1.2.2   rmarkdown_1.9   knitr_1.20     
#> [13] stringr_1.3.1   digest_0.6.18   evaluate_0.11
Created on 2019-03-21 by the [reprex package](https://reprex.tidyverse.org) (v0.2.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions