mysql - R中的序列化对象到mysql数据库

标签 mysql r serialization rmysql

如果我有序列化数据,例如:

> 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/

相关文章:

r - R 中的交互式散点图,叠加/悬停摘要/工具提示作为用户提供的绘图功能

r - 用 R 中的 colSums 划分列

mysql - Crystal Reports 中的分组结果,其中链接列有多个相关结果

mysql - 我可以执行一个只返回与通配符匹配的列的数据的查询吗?

r - 在 R 中绘制 data.frame

Django REST 序列化程序方法可写字段

ruby-on-rails - Rails 无法启动服务器序列化程序 has_many 错误

java - 尺寸较大但全为空值的对象列表

mysql - sql返回最普遍的列值

php - 如何多次更新一个字段?