加载RPostgreSQL包
>install.packages("RPostgreSQL")
>library(RPostgreSQL)
>Loading required package: DBI
建立数据库的driver 链接
>con = dbDriver("PostgreSQL")
填写数据库连接信息
>pgdb_con = dbConnect(con, user = "appform", password = "appform", host = "192.168.0.21")
查询语句
>data = dbSendQuery(pgdb_con, statement = "SELECT * FROM ab_user")
查看结果
>df = fetch(data, n = -1)
直接查询
>dbGetQuery(pgdb_con, "SQL语句")
断开连接
>dbDisconnect(pgdb_con)
退出链接
>dbUnloadDriver(con)