如果我有序列化数据,例如:
> a <- 1:5
> a
[1] 1 2 3 4 5
> b <- serialize(a,NULL)
> b
[1] 58 0a 00 00 00 02 00 02 0f 02 00 02 03 00 00 00 00 0d 00 00 00 05 00 00 00 01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00 05
> b[1]
[1] 58
> b[8]
[1] 02
如何将序列化数据放入 MySQL 表中?我那里还有其他信息。我读到它可以作为 blob 完成,但我不知道它是如何工作的。我正在使用 RMySQL。我已经尝试过:
dbGetQuery(con, "INSERT INTO table(",b," info, moreInfo, otherStuff, more, date )")
但这行不通。
如果我使用
query <- paste ("INSERT INTO table(",b," info, moreInfo, otherStuff, more, date )")
dbGetQuery(con,query)
还是不行。
最佳答案
试试这个:
library(RODBC)
dt=data.table(a=sample(10),b=sample(10)*10)
sqlSave(con, dt, tablename='sampletablename') # overwrites existing sampletablename table
sqlSave(con, dt, tablename='sampletablename', append=TRUE) # append instead of overwrite
关于mysql - R中的序列化对象到mysql数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16531097/