I cannot connect postgresql schema.table with dplyr package

孤街醉人 提交于 2019-12-02 18:20:35

Finally dplyr has the solution to this problem thanks to the latest version 0.7 recently announced by Hadley Wickham. The DBI and dbplyr libraries greatly simplified the connection between dplyr and PostgreSQL.

con <- DBI::dbConnect(RPostgreSQL::PostgreSQL(), 
host = "database.rstudio.com",
user = "hadley",
password = rstudioapi::askForPassword("Database password"))
tbl <- dplyr::tbl(con, dbplyr::in_schema('mortalidad','def0307'))
ph49

You might want this,

db=src_postgres(dbname = 'mdb1252',  
               user = "diego", password = "pass", options="-c search_path=mortalidad")

If anybody ends up here with the same problem, here is what works for me: (taken from @Diego's comment from Feb 6'14)

postgre_table <- function (src, schema, table) {
  paste('SELECT * FROM', paste(schema, table, sep = '.')) %>% 
    sql() %>% tbl(src = src)
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!