首页 > 解决方案 > RODBC:围绕 SQL Server APPENDS 的日期时间值引用

问题描述

基于上一个问题(此处),我在 R 中创建了一个数据框:

mdf <- structure(list(run = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("run_00", 
"run_01", "run_02", "run_03", "run_04"), class = "factor"), slot = structure(c(1L, 
1L, 1L, 1L, 1L, 1L), .Label = c("slot 3", "slot 4", "slot 5", 
"slot 6"), class = "factor"), timestamp = structure(c(1320774563, 
1320774624, 1320774686, 1320774747, 1320774809, 1320774871), class = c("POSIXct", 
"POSIXt"), tzone = ""), channel = structure(c(1L, 1L, 1L, 1L, 
1L, 1L), .Label = c("och01", "och02", "och09", "och10"), class = "factor"), 
variable = structure(c(2L, 2L, 2L, 2L, 2L, 2L), .Label = c("num_blocks", 
"num_collection", "num_corr_0", "num_corr_1", "num_uncorr_srow", 
"post_fec_err_rate", "pre_fec_err_rate"), class = "factor"), 
value = c(1, 62, 124, 185, 247, 309)), .Names = c("run", 
"slot", "timestamp", "channel", "variable", "value"), row.names = c(NA, 
6L), class = "data.frame")

> mdf
     run   slot           timestamp channel       variable value
1 run_00 slot 3 2011-11-08 12:49:23   och01 num_collection     1
2 run_00 slot 3 2011-11-08 12:50:24   och01 num_collection    62
3 run_00 slot 3 2011-11-08 12:51:26   och01 num_collection   124
4 run_00 slot 3 2011-11-08 12:52:27   och01 num_collection   185
5 run_00 slot 3 2011-11-08 12:53:29   och01 num_collection   247
6 run_00 slot 3 2011-11-08 12:54:31   och01 num_collection   309

然后我将这些数据保存到数据库中:

sqlSave(conout,mdf,tablename="mdf")

现在,我想将相同的数据附加到数据库中:

sqlSave(conout,mdf,tablename="mdf",fast=FALSE,append=TRUE, verbose=TRUE)

这会导致以下错误:

[RODBC] ERROR: Could not SQLExecDirect 'INSERT INTO "mdf" ( "rownames", "run", "slot", "timestamp", "channel", "variable", "value" ) VALUES ( '1', 'run_00', 'slot 3', 2011-11-08 17:49:23, 'och01', 'num_collection',   1 )'

我理解错误的原因,因为 R 应该在日期时间值“时间戳”(即“2011-11-08 17:49:23”)周围加上引号。但是,我不知道如何解决此错误。一些忠告?

包版本:1.3.15

编辑:如果提到其他问题,请解释一下他们能在多大程度上帮助我。

标签: sqlrsql-serverrodbc

解决方案


推荐阅读