我尝试从SQL Server导入数据,但是我在导入包含uniqueidentifier列类型的表时遇到问题。
我使用R Client 3.3.2.0查询数据库。
数据库表:
代码:
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.
答案 0 :(得分:0)
RxSqlServerData
不支持UNIQUEIDENTIFIER
数据类型。您应该将其转换为varchar。
sqlServerData <- RxSqlServerData(
sqlQuery = "select id, CONVERT(VARCHAR(36), ui) ui from tbl1",
connectionString = sqlConnString, colClasses = colClasses)