From f932ec6aaaf454dea8ed0a58973416f2cf342e53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 12 Sep 2021 17:38:22 +0200 Subject: [PATCH 1/4] Limitation: list only tables from top-level schema --- R/tables.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/tables.R b/R/tables.R index 5e0d3ac3..92d43ef3 100644 --- a/R/tables.R +++ b/R/tables.R @@ -282,6 +282,8 @@ find_table <- function(conn, id, inf_table = "tables", only_first = FALSE) { dbQuoteString(conn, id[["schema"]]), "::varchar", " AS table_schema) t" ) + } else if (is(conn, "RedshiftConnection")) { + query <- "(SELECT 1 AS nr, current_schema() AS table_schema) ttt" } else { # https://stackoverflow.com/a/8767450/946850 query <- paste0( From 777cc07b8eb5791feb2a58149b78ca5c63d36696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Mon, 13 Sep 2021 16:45:23 +0200 Subject: [PATCH 2/4] Fix dbExistsTable() --- R/tables.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/tables.R b/R/tables.R index 92d43ef3..46dad3d7 100644 --- a/R/tables.R +++ b/R/tables.R @@ -276,14 +276,17 @@ exists_table <- function(conn, id) { } find_table <- function(conn, id, inf_table = "tables", only_first = FALSE) { + is_redshift <- is(conn, "RedshiftConnection") + if ("schema" %in% names(id)) { query <- paste0( "(SELECT 1 AS nr, ", dbQuoteString(conn, id[["schema"]]), "::varchar", " AS table_schema) t" ) - } else if (is(conn, "RedshiftConnection")) { + } else if (is_redshift) { query <- "(SELECT 1 AS nr, current_schema() AS table_schema) ttt" + only_first <- FALSE } else { # https://stackoverflow.com/a/8767450/946850 query <- paste0( From 3bf68d62ff7aaa1e506343eade9003141176b48d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Mon, 13 Sep 2021 16:45:32 +0200 Subject: [PATCH 3/4] Fix dbListOBjects() --- R/tables.R | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/R/tables.R b/R/tables.R index 46dad3d7..aa3e757b 100644 --- a/R/tables.R +++ b/R/tables.R @@ -378,12 +378,17 @@ list_fields <- function(conn, id) { setMethod("dbListObjects", c("PqConnection", "ANY"), function(conn, prefix = NULL, ...) { query <- NULL if (is.null(prefix)) { + if (is(conn, "RedshiftConnection")) { + in_current_schema <- "table_schema = current_schema()" + } else { + in_current_schema <- "(table_schema = ANY(current_schemas(true))) AND (table_schema <> 'pg_catalog')" + } query <- paste0( - "SELECT NULL AS schema, table_name AS table FROM INFORMATION_SCHEMA.tables\n", + "SELECT NULL::varchar(max) AS schema, table_name AS table FROM INFORMATION_SCHEMA.tables\n", "WHERE ", - "(table_schema = ANY(current_schemas(true))) AND (table_schema <> 'pg_catalog')\n", + in_current_schema, "\n", "UNION ALL\n", - "SELECT DISTINCT table_schema AS schema, NULL AS table FROM INFORMATION_SCHEMA.tables" + "SELECT DISTINCT table_schema AS schema, NULL::varchar(max) AS table FROM INFORMATION_SCHEMA.tables" ) } else { unquoted <- dbUnquoteIdentifier(conn, prefix) From fffbedcacfdfa394932144f6d6fa38e26464473b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Mon, 13 Sep 2021 20:51:42 +0200 Subject: [PATCH 4/4] (max) incompatible with Postgres --- R/tables.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/tables.R b/R/tables.R index aa3e757b..06c8f825 100644 --- a/R/tables.R +++ b/R/tables.R @@ -384,11 +384,11 @@ setMethod("dbListObjects", c("PqConnection", "ANY"), function(conn, prefix = NUL in_current_schema <- "(table_schema = ANY(current_schemas(true))) AND (table_schema <> 'pg_catalog')" } query <- paste0( - "SELECT NULL::varchar(max) AS schema, table_name AS table FROM INFORMATION_SCHEMA.tables\n", + "SELECT NULL::varchar AS schema, table_name AS table FROM INFORMATION_SCHEMA.tables\n", "WHERE ", in_current_schema, "\n", "UNION ALL\n", - "SELECT DISTINCT table_schema AS schema, NULL::varchar(max) AS table FROM INFORMATION_SCHEMA.tables" + "SELECT DISTINCT table_schema AS schema, NULL::varchar AS table FROM INFORMATION_SCHEMA.tables" ) } else { unquoted <- dbUnquoteIdentifier(conn, prefix)