为了账号安全,请及时绑定邮箱和手机立即绑定

A fast, easy-to-use database library for R

标签:
Java

Postgres

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)

MySQL

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

SQLite

install.packages("RSQLite")

library(dbx)

db <- dbxConnect(adapter="sqlite", dbname=":memory:")

SQL Server

install.packages("odbc")
library(dbx)

db <- dbxConnect(adapter=odbc::odbc(), database="mydb")

You can also pass uid, pwd, server, and port.

Redshift

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


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

举报

0/150
提交
取消