From 6539807e3f5bda0844e262d2c4cac8420fcb02cd Mon Sep 17 00:00:00 2001 From: Daniel Possenriede Date: Mon, 28 Sep 2020 14:11:40 +0200 Subject: [PATCH] dbListTables: list materialized views as well, #251 use pg_class/pg_namespace instead of information_schema.tables --- R/tables.R | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/R/tables.R b/R/tables.R index 0897817e..f5937259 100644 --- a/R/tables.R +++ b/R/tables.R @@ -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]] })