Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion R/ListTables.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ setMethod(
catalog = cleanSchemaName(databaseSchema[1]),
schema = cleanSchemaName(databaseSchema[2])
)
} else if (!is.null(databaseSchema) && dbms(conn) == "duckdb") {
} else if (!is.null(databaseSchema) && dbms(conn) %in% c("duckdb", "postgresql", "redshift")) {
# Some DBI drivers (e.g. RPostgres) ignore the schema argument of dbListTables():
if (grepl("\\.", databaseSchema)) {
databaseSchema <- strsplit(databaseSchema, "\\.")[[1]][2]
}
Expand Down
21 changes: 21 additions & 0 deletions tests/testthat/test-getTableNames.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,24 @@ for (testServer in testServers) {

})
}

test_that("Get table names in schema using a DBI Postgres connection", {
skip_if(Sys.getenv("CDM5_POSTGRESQL_SERVER") == "", "No Postgres test server")
skip_if_not_installed("RPostgres")
parts <- unlist(strsplit(Sys.getenv("CDM5_POSTGRESQL_SERVER"), "/"))
connectionDetails <- createDbiConnectionDetails(
dbms = "postgresql",
drv = RPostgres::Postgres(),
dbname = parts[2],
host = parts[1],
user = Sys.getenv("CDM5_POSTGRESQL_USER"),
password = URLdecode(Sys.getenv("CDM5_POSTGRESQL_PASSWORD"))
)
connection <- connect(connectionDetails)
on.exit(disconnect(connection))
cdmDatabaseSchema <- Sys.getenv("CDM5_POSTGRESQL_CDM54_SCHEMA")
tables <- getTableNames(connection, cdmDatabaseSchema)
expect_true("person" %in% tables)
expect_true(existsTable(connection, cdmDatabaseSchema, "person"))
expect_false(existsTable(connection, "non_existing_schema", "person"))
})
Loading