在使用 RODBC 从 R 连接到 GreenPlum PostgreSQL 数据库时,我遇到了一个以前从未遇到过的新错误。我使用 EMACS/ESS 和 RStudio 都遇到了错误,并且 RODBC 调用与过去一样工作。
library(RODBC)
gp <- odbcConnect("greenplum", believeNRows = FALSE)
data <- sqlQuery(gp, "select * from mytable")
> data
[1] "22P05 7 ERROR: character 0xc280 of encoding \"UTF8\" has no equivalent in "WIN1252\";\nError while executing the query"
[2] "[RODBC] ERROR: Could not SQLExecDirect 'select * from mytable'"
编辑:刚刚尝试查询另一个表并得到了结果。所以我猜这不是 RODBC 问题,而是 PostgreSQL 表编码问题。
R version 2.13.0 (2011-04-13)
Platform: i386-pc-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] RODBC_1.3-2
>