Skip to content

Commit 6539807

Browse files
committed
dbListTables: list materialized views as well, r-dbi#251
use pg_class/pg_namespace instead of information_schema.tables
1 parent 5e29546 commit 6539807

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

R/tables.R

+8-3
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,14 @@ setMethod("dbReadTable", c("PqConnection", "character"),
236236
#' @rdname postgres-tables
237237
setMethod("dbListTables", "PqConnection", function(conn, ...) {
238238
query <- paste0(
239-
"SELECT table_name FROM INFORMATION_SCHEMA.tables ",
240-
"WHERE ",
241-
"(table_schema = ANY(current_schemas(true))) AND (table_schema <> 'pg_catalog')"
239+
# pg_class docs: https://www.postgresql.org/docs/current/catalog-pg-class.html
240+
"SELECT cl.relname AS name FROM pg_class AS cl ",
241+
"JOIN pg_namespace AS n ON cl.relnamespace = n.oid ",
242+
"WHERE (n.nspname = ANY (current_schemas(true))) ",
243+
"AND (n.nspname <> 'pg_catalog') ",
244+
"AND (cl.relkind IN ('r', 'p', 'f', 'v', 'm')) ",
245+
"AND NOT cl.relispartition ",
246+
"ORDER BY name"
242247
)
243248
dbGetQuery(conn, query)[[1]]
244249
})

0 commit comments

Comments
 (0)