PostgreSQL的rodbc字符编码错误

PostgreSQL的rodbc字符编码错误

本文介绍了PostgreSQL的rodbc字符编码错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 RODBC 从 R 连接到 GreenPlum PostgreSQL 数据库时,我遇到了一个我以前从未遇到过的新错误.我在使用 EMACS/ESS 和 RStudio 时都遇到了错误,而且 RODBC 调用一直正常工作.

I'm getting a new error which I've never gotten before when connecting from R to a GreenPlum PostgreSQL database using RODBC. I've gotten the error using both EMACS/ESS and RStudio, and the RODBC call has worked as is in the past.

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 表编码问题.

Just tried querying another table and did get results. So I guess it's not an RODBC problem but a PostgreSQL table encoding problem.

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
>

推荐答案

首先,出现这个问题是因为 R 试图转换为支持 UTF8 的 Windows 语言环境.不幸的是,Brian Ripley 多次报告说 Windows 没有 UTF8 语言环境.通过在网络、StackOverflow、Microsoft 等上花费的时间搜索,我得出的结论是 Microsoft Windows 不支持 UTF8.

First, the issue arises because R is trying to convert to a Windows locale that supports UTF8. Unfortunately, Brian Ripley has reported numerous times that Windows has no UTF8 locales. From hours spent searching the web, StackOverflow, Microsoft, etc., I have come to the conclusion that Microsoft Windows won't support UTF8.

因此,如果有任何解决方案,我不确定是否有简单的解决方案.我能推荐的最好方法是在服务器端进行某种转换,如果可以,请查看过滤数据,或者在适当的情况下尝试不同的语言(例如中文、日语、韩语).

As a result, I'm not sure that there's an easy solution to this, if there is any solution at all. The best I can recommend is to wrap some kind of conversion on the server side, look at filtering the data if you can, or try a different language, if appropriate (e.g. Chinese, Japanese, Korean).

如果您决定封装转换器,unicode.org 建议 这个 ICU 工具包.

If you do decide to wrap a converter, unicode.org recommends this ICU toolkit.

这篇关于PostgreSQL的rodbc字符编码错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 03:28