R语言操作postgresql

#加载库
require(RPostgreSQL) 
# 读入driver 
drv = dbDriver("PostgreSQL") 
# 填写连接信息
pgdb_con = dbConnect(drv, user="user", password="password",host="127.0.0.1")
# 查询语句 
rs = dbSendQuery(pgdb_con, statement = "SQL语句") 
# 收割结果 
df = fetch(rs, n = -1) 
# 其实可以直接执行查询返回结果 
dbGetQuery(pgdb_con, "SQL语句") 
# 断开连接 
dbDisconnect(pgdb_con) 
# 释放资源 
dbUnloadDriver(drv) 

你可能感兴趣的:(PostgreSQL)