rhandsontable 使用 dbWriteTable 将 NULL 值写入 SQL 数据库

rhandsontable writing NULL values to SQL database using dbWriteTable

我正在使用库 (rhandsontable)

创建以下 table
rhandsontable(df, className = "htCenter", stretchH = "all", columnSorting = TRUE) %>%
         hot_col("Date", type = "date", dateFormat = "YYYY-MM-DD") %>%
         hot_cols(format = '1')

table 转换为数据框 dfHot <- hot_to_r(input$hot),然后复制到 SSMS SQL 数据库

dbWriteTable(con, "TEST", dfHot, append = TRUE, overwrite = FALSE, row.names = FALSE)

问题是 table 可以包含 NULL 值,这些值在 R 中显示为 NA,但我需要它们在 NULL 中显示为 [=30] =].

当 table 中存在 NA 值时出现此错误:

Warning: Error in .local: execute JDBC update query failed in dbSendUpdate (The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 6 (""): The supplied value is not a valid instance of data type float. Check the source data for invalid values. An example of an invalid value is data of numeric type with scale greater than precision.)

如果不存在 NA 值,则 table 导入没有任何问题。

我没有使用 dbWriteTable,而是通过将 VALUES 插入 SQL 解决了这个问题。在此处找到详细信息:https://www.pmg.com/blog/insert-r-data-frame-sql%EF%BB%BF/