revoscaler sqlServerdData rxImport uniqueidentifier列失败

时间:2018-02-13 11:36:54

标签: sql-server r revoscaler

我尝试从SQL Server导入数据,但是我在导入包含uniqueidentifier列类型的表时遇到问题。

我使用R Client 3.3.2.0查询数据库。

数据库表:

enter image description here

代码:

sqlConnString = "DRIVER=ODBC Driver 11 for SQL Server;SERVER=JDIMKO;DATABASE=Test;UID=sa;PWD=***;"

colClasses = c("id" = "integer", "ui" = "character")

sqlServerData <- RxSqlServerData(
    sqlQuery = "select * from tbl1",
    connectionString = sqlConnString, colClasses = colClasses)

custData = rxImport(sqlServerData)

错误:

Unhandled SQL data type!!! 
Unhandled SQL data type!!! 
Could not open data source.
Error in doTryCatch(return(expr), name, parentenv, handler) : 
  Could not open data source.

1 个答案:

答案 0 :(得分:0)

RxSqlServerData不支持UNIQUEIDENTIFIER数据类型。您应该将其转换为varchar。

sqlServerData <- RxSqlServerData(
    sqlQuery = "select id, CONVERT(VARCHAR(36), ui) ui from tbl1",
    connectionString = sqlConnString, colClasses = colClasses)