使用RpostgreSQL在循环内更改PostgreSQL架构

使用RpostgreSQL在循环内更改PostgreSQL架构,r,postgresql,dplyr,rpostgresql,R,Postgresql,Dplyr,Rpostgresql,我在PostgreSQL中有一堆相同的模式,我想从中获取数据。我以这种方式在循环中使用RpostgreSQL ``` r results <- data.frame() for (schema in schema.list ) { con <- DBI::dbConnect(RPostgreSQL::PostgreSQL(), user = 'user', password =

我在PostgreSQL中有一堆相同的模式,我想从中获取数据。我以这种方式在循环中使用RpostgreSQL

``` r

results <- data.frame()

for (schema in schema.list ) {


  con <- DBI::dbConnect(RPostgreSQL::PostgreSQL(),
                        user = 'user',
                        password = 'pwd',
                        dbname = 'mydb',
                        host = 'myhost.com',
                        options = paste0(" -c search_path=", schema)

  )

  tbl <- dplyr::tbl(con, sql(my_sql_query)) %>% collect()

  results <- rbind(results,tbl)

  dbDisconnect(con)

}
``r

结果问题:您是在同一个最终数据帧中获得多个数据块,还是代码的行为就像循环只使用最后一个模式迭代一次一样?我会打印每个模式名称,但我只会看到访问的唯一模式是最后一个模式。有一次,我推测
search\u path
参数被忽略了,并且使用了一些默认模式。你能在你的问题中包括
schema.list
?您能直接从命令行成功地连接到这些模式中的每一个吗?是的,我能连接到每一个模式。我看不出您的代码有任何错误。这里可能很难找到答案,因为大多数人无法重现你的问题。在任何情况下都要投票表决。