Skip to content

Commit

Permalink
dbListTables: list materialized views as well, r-dbi#251
Browse files Browse the repository at this point in the history
use pg_class/pg_namespace instead of information_schema.tables
  • Loading branch information
dpprdan committed Sep 28, 2020
1 parent 5e29546 commit 6539807
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions R/tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,14 @@ setMethod("dbReadTable", c("PqConnection", "character"),
#' @rdname postgres-tables
setMethod("dbListTables", "PqConnection", function(conn, ...) {
query <- paste0(
"SELECT table_name FROM INFORMATION_SCHEMA.tables ",
"WHERE ",
"(table_schema = ANY(current_schemas(true))) AND (table_schema <> 'pg_catalog')"
# pg_class docs: https://www.postgresql.org/docs/current/catalog-pg-class.html
"SELECT cl.relname AS name FROM pg_class AS cl ",
"JOIN pg_namespace AS n ON cl.relnamespace = n.oid ",
"WHERE (n.nspname = ANY (current_schemas(true))) ",
"AND (n.nspname <> 'pg_catalog') ",
"AND (cl.relkind IN ('r', 'p', 'f', 'v', 'm')) ",
"AND NOT cl.relispartition ",
"ORDER BY name"
)
dbGetQuery(conn, query)[[1]]
})
Expand Down

0 comments on commit 6539807

Please sign in to comment.