I cannot connect postgresql schema.table with dplyr package

后端 未结 3 1140
陌清茗
陌清茗 2021-02-01 06:04

Im trying to connect postgres with dplyr functions

my_db <- src_postgres(dbname = \'mdb1252\', user = \"diego\", password = \"pass\")
my_db
src:  postgres 9.2         


        
相关标签:
3条回答
  • 2021-02-01 06:39

    You might want this,

    db=src_postgres(dbname = 'mdb1252',  
                   user = "diego", password = "pass", options="-c search_path=mortalidad")
    
    0 讨论(0)
  • 2021-02-01 06:50

    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)
    }
    
    0 讨论(0)
  • 2021-02-01 06:52

    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'))
    
    0 讨论(0)
提交回复
热议问题