考虑使用dplyr向表中添加数据,我看到https://stackoverflow.com/a/26784801/1653571,但文档说db_insert_table()
已弃用。
?db_insert_into()
...
db_create_table() and db_insert_into() have been deprecated in favour of db_write_table().
...
我尝试使用未弃用的db_write_table()
,但无论有没有append=
选项都失败了:
require(dplyr)
my_db <- src_sqlite( "my_db.sqlite3", create = TRUE) # create src
copy_to( my_db, iris, "my_table", temporary = FALSE) # create table
newdf = iris # create new data
db_write_table( con = my_db$con, table = "my_table", values = newdf) # insert into
# Error: Table `my_table` exists in database, and both overwrite and append are FALSE
db_write_table( con = my_db$con, table = "my_table", values = newdf,append=True) # insert into
# Error: Table `my_table` exists in database, and both overwrite and append are FALSE
是否可以使用db_write_table()
附加数据?
答案 0 :(得分:0)
不,你不应该使用db_write_table()而不是db_insert_table(),因为它不能在后端进行泛化。
并且你不应该使用tidyverse版本而不是相关的DBI :::版本,因为tidyverse辅助函数是供内部使用的,并且设计得不够健壮以供用户使用。请参阅https://github.com/tidyverse/dplyr/issues/3120#issuecomment-339034612上的讨论:
实际上,我认为你根本不应该使用这些功能。尽管如此SO帖子,这些不是面向用户的功能。你应该直接调用DBI函数 - 包装作者Hadley Wickham。