我是 R 的新手,我正在尝试使用 RStudio 连接到 PostgreSQL。

我已经安装了 RPostgreSQL 并尝试了以下代码:

> library("DBI", lib.loc="~/R/win-library/3.2")
> library("RPostgreSQL", lib.loc="~/R/win-library/3.2")
> con <- dbConnect(dbDriver("PostgreSQL"), dbname="Delta", user="postgres")
Error in postgresqlNewConnection(drv, ...) :
  RS-DBI driver: (could not connect postgres@local on dbname "Delta"

由于某种原因,我无法连接到数据库。我试图解决这个问题很长时间,但不知道如何解决。

最佳答案

我对这个问题的解决方案是使用 RPostgres https://github.com/rstats-db/RPostgres

假设您有一个连接 url ,以下代码将起作用:

library(DBI)
library(RPostgres)

con <- dbConnect(RPostgres::Postgres(),
  host = url$host,
  port = url$port,
  dbname = url$dbname,
  user = url$user,
  password = url$password
)

关于r - postgresqlNewConnection(drv, ...) RS-DBI 驱动程序中的错误 : (could not connect postgres@local on dbname,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36026436/

10-13 05:51