2 years ago
#53123
jfz88
dBWriteTable cannot write more than one record (with NA) into into SQL Server table
I am using RJDBC and dbWriteTable to write a data.table into an existing SQL Server database table. Here is my sample data: mtcars
After I get connection to DB, I am using dbWriteTable to create a DB table "mtcars".
dbWriteTable(conn, "mtcars", mtcars[1:5, ])
Next use append=T to insert two rows: dbWriteTable(conn.pre.alg, "mtcars",mtcars[6:7, ], append = T)
Then I set a NA in a row: mtcars[8, 2] = NA
I can insert the record without any problem. dbWriteTable(conn.pre.alg, "mtcars",mtcars[8, ], append = T)
But when I set NA in a row and try to insert two rows: mtcars[9:10, 2] = NA dbWriteTable(conn.pre.alg, "mtcars",mtcars[9:10, ], append = T)
I get an error: Error in .local(conn, statement, ...) : execute JDBC update query failed in dbSendUpdate (The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 4 (""): 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.)
I tried to set field.types, but I still get the same error.
r
sql-server
jdbc
datatable
rjdbc
0 Answers
Your Answer