Skip to content

Encoding of column names and error messages #172

Closed

Description

@etienne-s

con is a connection to a Postgres DB.

dbGetQuery(con, "select 'é' as é")
#   é
# 1  é

dbGetQuery(con, "é")
# Error in result_create(conn@ptr, statement) : 
#   Failed to prepare query: ERROR:  syntax error at or near "é"
# LINE 1: é
#         ^

In both cases é should be displayed instead of é.

Session info
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252    LC_MONETARY=French_France.1252
[4] LC_NUMERIC=C                   LC_TIME=French_France.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] DBI_0.7

loaded via a namespace (and not attached):
 [1] bit_1.1-12      compiler_3.4.3  hms_0.4.1       tools_3.4.3     pillar_1.1.0    tibble_1.4.2    yaml_2.1.16    
 [8] Rcpp_0.12.15    bit64_0.9-7     blob_1.1.0      pkgconfig_2.0.1 rlang_0.1.6     RPostgres_1.0-4

Activity

  1. dpprdan commented on Feb 14, 2019

    @dpprdan
    Contributor

    I can confirm this issue. Full reprex:

    library(RPostgres)
    
    pg_con <- 
      dbConnect(
        RPostgres::Postgres(),
        user = Sys.getenv("pg_localhost_user"),
        password = Sys.getenv("pg_localhost_user"), 
        dbname = "postgres"
      )
    
    dfx <- data.frame(`fläche` = 42L, stringsAsFactors = FALSE)
    # Encode colnames as UTF-8 or else dbWriteTable will throw an error
    colnames(dfx) <- enc2utf8(colnames(dfx))
    
    dbGetQuery(pg_con, "SHOW server_encoding")
    #>   server_encoding
    #> 1            UTF8
    dbGetQuery(pg_con, "SHOW client_encoding")
    #>   client_encoding
    #> 1            UTF8
    
    dbWriteTable(pg_con, "dfx", dfx, temporary = TRUE)
    
    (dbx <- dbReadTable(pg_con, "dfx"))
    #>   flÃ.che
    #> 1      42
    
    dbDisconnect(pg_con)
    Session info
    devtools::session_info()
    #> - Session info ----------------------------------------------------------
    #>  setting  value                       
    #>  version  R version 3.5.2 (2018-12-20)
    #>  os       Windows 10 x64              
    #>  system   x86_64, mingw32             
    #>  ui       RTerm                       
    #>  language en                          
    #>  collate  German_Germany.1252         
    #>  ctype    German_Germany.1252         
    #>  tz       Europe/Berlin               
    #>  date     2019-02-14                  
    #> 
    #> - Packages --------------------------------------------------------------
    #>  package     * version    date       lib source                        
    #>  assertthat    0.2.0      2017-04-11 [1] CRAN (R 3.5.1)                
    #>  backports     1.1.3      2018-12-14 [1] CRAN (R 3.5.1)                
    #>  bit           1.1-14     2018-05-29 [1] CRAN (R 3.5.0)                
    #>  bit64         0.9-7      2017-05-08 [1] CRAN (R 3.5.0)                
    #>  blob          1.1.1      2018-03-25 [1] CRAN (R 3.5.1)                
    #>  callr         3.1.1      2018-12-21 [1] CRAN (R 3.5.2)                
    #>  cli           1.0.1      2018-09-25 [1] CRAN (R 3.5.1)                
    #>  crayon        1.3.4      2017-09-16 [1] CRAN (R 3.5.1)                
    #>  DBI           1.0.0      2018-05-02 [1] CRAN (R 3.5.1)                
    #>  desc          1.2.0      2018-05-01 [1] CRAN (R 3.5.1)                
    #>  devtools      2.0.1      2018-10-26 [1] CRAN (R 3.5.1)                
    #>  digest        0.6.18     2018-10-10 [1] CRAN (R 3.5.1)                
    #>  evaluate      0.13       2019-02-12 [1] CRAN (R 3.5.2)                
    #>  fs            1.2.6      2018-08-23 [1] CRAN (R 3.5.1)                
    #>  glue          1.3.0      2018-07-17 [1] CRAN (R 3.5.1)                
    #>  highr         0.7        2018-06-09 [1] CRAN (R 3.5.1)                
    #>  hms           0.4.2.9001 2019-01-23 [1] Github (tidyverse/hms@cb175bb)
    #>  htmltools     0.3.6      2017-04-28 [1] CRAN (R 3.5.1)                
    #>  knitr         1.21       2018-12-10 [1] CRAN (R 3.5.1)                
    #>  magrittr      1.5        2014-11-22 [1] CRAN (R 3.5.1)                
    #>  memoise       1.1.0      2017-04-21 [1] CRAN (R 3.5.1)                
    #>  pkgbuild      1.0.2      2018-10-16 [1] CRAN (R 3.5.1)                
    #>  pkgconfig     2.0.2      2018-08-16 [1] CRAN (R 3.5.1)                
    #>  pkgload       1.0.2      2018-10-29 [1] CRAN (R 3.5.1)                
    #>  prettyunits   1.0.2      2015-07-13 [1] CRAN (R 3.5.1)                
    #>  processx      3.2.1      2018-12-05 [1] CRAN (R 3.5.1)                
    #>  ps            1.3.0      2018-12-21 [1] CRAN (R 3.5.2)                
    #>  R6            2.3.0      2018-10-04 [1] CRAN (R 3.5.1)                
    #>  Rcpp          1.0.0      2018-11-07 [1] CRAN (R 3.5.1)                
    #>  remotes       2.0.2      2018-10-30 [1] CRAN (R 3.5.1)                
    #>  rlang         0.3.1      2019-01-08 [1] CRAN (R 3.5.2)                
    #>  rmarkdown     1.11       2018-12-08 [1] CRAN (R 3.5.1)                
    #>  RPostgres   * 1.1.1      2018-05-06 [1] CRAN (R 3.5.1)                
    #>  rprojroot     1.3-2      2018-01-03 [1] CRAN (R 3.5.1)                
    #>  sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 3.5.1)                
    #>  stringi       1.2.4      2018-07-20 [1] CRAN (R 3.5.1)                
    #>  stringr       1.4.0      2019-02-10 [1] CRAN (R 3.5.2)                
    #>  testthat      2.0.1      2018-10-13 [1] CRAN (R 3.5.1)                
    #>  usethis       1.4.0      2018-08-14 [1] CRAN (R 3.5.1)                
    #>  withr         2.1.2      2018-03-15 [1] CRAN (R 3.5.1)                
    #>  xfun          0.4        2018-10-23 [1] CRAN (R 3.5.1)                
    #>  yaml          2.2.0      2018-07-25 [1] CRAN (R 3.5.1)                
    #> 
    #> [1] C:/Users/daniel/Documents/.R/win-library
    #> [2] C:/Program Files/R/R-3.5.2/library
  2. krlmlr commented on Mar 3, 2019

    @krlmlr
    Member

    Thanks for the reprex. I think the std::vector<std::string> names; should be a CharacterVector instead, and populated with strings tagged as UTF-8.

  3. krlmlr commented on Jul 8, 2019

    @krlmlr
    Member

    Do the recent changes resolve the problem? Seems to work on my system.

  4. github-actions commented on Dec 7, 2020

    @github-actions
    Contributor

    This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.

  5. locked and limited conversation to collaborators on Dec 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions