Open abalter opened 1 year ago
Thanks. Can you use dbListObjects()
?
library(DBI)
con <- DBI::dbConnect(RPostgres::Postgres())
dbExecute(con, "create schema if not exists test;")
#> [1] 0
dbWriteTable(con, Id(schema = "test", table = "iris"), iris, overwrite = TRUE)
dbListObjects(con, DBI::Id(schema = "test"))
#> table is_prefix
#> 1 <Id> schema = test, table = iris FALSE
dbExecute(con, "drop schema test cascade")
#> NOTICE: drop cascades to table test.iris
#> [1] 0
dbDisconnect(con)
Created on 2023-04-01 with reprex v2.0.2
This might be broken still, or again. We switched to unnamed components in Id()
, tracking in https://github.com/r-dbi/DBItest/issues/340 and https://github.com/r-dbi/DBItest/issues/367.
This might be broken still, or again.
FWIW dbListObjects()
works with named Id()
as prefix
, but does not (i.e. returns an empty result!) with an unnamed Id()
.
library(RPostgres)
con <- dbConnect(Postgres())
dbExecute(con, "create schema if not exists test;")
#> [1] 0
dbWriteTable(con, Id(schema = "test", table = "iris"), iris, overwrite = TRUE)
dbListObjects(con, Id(schema = "test"))
#> table is_prefix
#> 1 <Id> "test"."iris" FALSE
dbListObjects(con, Id("test"))
#> [1] table is_prefix
#> <0 rows> (or 0-length row.names)
dbExecute(con, "drop schema test cascade")
#> NOTICE: drop cascades to table test.iris
#> [1] 0
dbDisconnect(con)
BTW This is the same for RMariaDB.
Yeah, dbListObjects()
can't work with unnamed Id()
. The function will still return named "Id"
objects that can be consumed.
I'm using the
RPostgres::Postgres()
driver. I can't get DBI to respect schema without using SQL. These two give different results:I don't know what I could do to make a reprex here.