问题描述
我正在使用RODBC将数据从MySql Server提取到R中.
因此,在数据库的一列中是一个字符向量
I am fetching data from MySql Server into R using RODBC.
So in one column of the database is a character vector
SELECT MAX(CHAR_LENGTH(column)) FROM reqtable;
返回26566
现在,我将向您展示一个示例,说明我是如何遇到问题的
Now I will show you an example how I am running into the problem
`library(RODBC)
con <- odbcConnect("mysqlcon")
rslts <- as.numeric(sqlQuery(con,
"SELECT CHAR_LENGTH(column) FROM reqtable LIMIT 10",
as.is=TRUE)[,1])
`返回
> rslts
[1] 62 31 17 103 30 741 28 73 25 357
其中rslts <- nchar(as.character(sqlQuery(con, "SELECT column FROM reqtable LIMIT 10", as.is=TRUE)[,1]))
返回
where asrslts <- nchar(as.character(sqlQuery(con, "SELECT column FROM reqtable LIMIT 10", as.is=TRUE)[,1]))
returns
> rslts
[1] 62 31 17 103 30 255 28 73 25 255
所以长度大于255的字符串将在255处被截断.有没有办法我可以获取完整的字符串.
So strings with length > 255 is getting truncated at 255. Is there a way I can get the full string.
谢谢
推荐答案
PostgreSQL ODBC驱动程序有一个名为MaxLongVarcharSize的变量,我发现默认情况下将其设置为8190(我在Windows和Ubuntu上都使用过). MySQL ODBC驱动程序可能将类似的变量设置为255.
The PostgreSQL ODBC driver has a variable called MaxLongVarcharSize that I have found set to 8190 by default (I've used it both on Windows and Ubuntu). It is possible that the MySQL ODBC driver has a similar variable set to 255.
这篇关于RODBC字符串被截断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!