install.packages("RPostgres")
library(dbx)
db <- dbxConnect(adapter="postgres", dbname="mydb")
You can also pass user, password, host, port, and url.
RPostgreSQL数据库也是这样操作的
举个例子,完整的连接因该是:
db <- dbxConnect(adapter = "postgres", dbname = " data", host = "test.cls0csjdlwvj.us-west-2.redshift.amazonaws.com", user='milin', password='Milin123', port=5439)
install.packages("RMySQL")
library(dbx)
db <- dbxConnect(adapter="mysql", dbname="mydb")
You can also pass user, password, host, port, and url and Works with RMariaDB as well
install.packages("RSQLite")
library(dbx)
db <- dbxConnect(adapter="sqlite", dbname=":memory:")
install.packages("odbc")
library(dbx)
db <- dbxConnect(adapter=odbc::odbc(), database="mydb")
You can also pass uid, pwd, server, and port.
For Redshift, follow the Postgres instructions.
records <- dbxSelect(db, "SELECT * FROM forecasts")
设置参数
dbxSelect(db, "SELECT * FROM forecasts WHERE period = ? AND temperature > ?", params=list("hour", 27))
table <- "forecasts"records <- data.frame(temperature=c(32, 25)) dbxInsert(db, table, records)
If you use auto-incrementing ids in Postgres, you can get the ids of newly inserted rows by passing the column name:
dbxInsert(db, table, records, returning=c("id"))
records <- data.frame(id=c(1, 2), temperature=c(16, 13))dbxUpdate(db, table, records, where_cols=c("id"))
bad_records <- data.frame(id=c(1, 2))dbxDelete(db, table, where=bad_records)
作者:Liam_ml
链接:https://www.jianshu.com/p/b535cf5a0702
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3996/viewspace-2819436/ ,如需转载,请注明出处,否则将追究法律责任。