我发现R挂起的情况是由于sqlSave没有处理插入的列多于表中存在的列的情况。
有没有人对我如何解决这种行为有任何见解?我有想法检索表中已有的列数,但这将是一个显着的性能消耗,并增加了代码的复杂性。
错误(再现将需要本地dsn /数据库连接)
channel <- odbcConnect("mydb")
odbcClearError(channel)
sqlSave(channel, dat=data.frame(a=1:3,b=letters[1:3]),
tablename="R_update_test",
# rownames=FALSE,
append=TRUE)
odbcClose(channel)
或者
channel <- odbcConnect("mydb")
odbcClearError(channel)
sqlSave(channel, dat=data.frame(a=1:3,b=letters[1:3],c=letters[1:3])]),
tablename="R_update_test",
rownames=FALSE,
append=TRUE)
odbcClose(channel)
sessionInfo包含在下面,目标db是mysql 5.6
> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-pc-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=C LC_COLLATE=C LC_MONETARY=C LC_MESSAGES=C
[7] LC_PAPER=C LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=C LC_IDENTIFICATION=C
attached base packages:
[1] splines grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] data.table_1.8.10 Hmisc_3.13-0 Formula_1.1-1 survival_2.37-4 caret_5.17-7 reshape2_1.2.2 plyr_1.8
[8] lattice_0.20-24 foreach_1.4.1 cluster_1.14.4 RODBC_1.3-9 Nemo_1.0 testthat_0.7.1 devtools_1.4
loaded via a namespace (and not attached):
[1] MASS_7.3-29 RColorBrewer_1.0-5 RCurl_1.95-4.1 codetools_0.2-8 colorspace_1.2-4 dichromat_2.0-0 digest_0.6.3
[8] evaluate_0.5.1 ggplot2_0.9.3.1 gtable_0.1.2 httr_0.2 iterators_1.0.6 labeling_0.2 memoise_0.1
[15] munsell_0.4.2 parallel_3.0.2 proto_0.3-10 scales_0.2.3 stringr_0.6.2 tools_3.0.2 whisker_0.3-2