Skip to content

Commit

Permalink
Use ::varchar(max) syntax on Redshift only, support current_schemas()
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Sep 14, 2021
1 parent e0cc15d commit 043f6d6
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions R/tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -381,18 +381,19 @@ list_fields <- function(conn, id) {
#' @rdname postgres-tables
setMethod("dbListObjects", c("PqConnection", "ANY"), function(conn, prefix = NULL, ...) {
query <- NULL
is_redshift <- is(conn, "RedshiftConnection")

if (is.null(prefix)) {
if (is(conn, "RedshiftConnection")) {
in_current_schema <- "table_schema = current_schema()"
if (is_redshift) {
null_varchar <- "NULL::varchar(max)"
} else {
in_current_schema <- "(table_schema = ANY(current_schemas(true))) AND (table_schema <> 'pg_catalog')"
null_varchar <- "NULL"
}
query <- paste0(
"SELECT NULL::varchar AS schema, table_name AS table FROM INFORMATION_SCHEMA.tables\n",
"WHERE ",
in_current_schema, "\n",
"SELECT ", null_varchar, " AS schema, table_name AS table FROM INFORMATION_SCHEMA.tables\n",
"WHERE (table_schema = ANY(current_schemas(true))) AND (table_schema <> 'pg_catalog')\n",
"UNION ALL\n",
"SELECT DISTINCT table_schema AS schema, NULL::varchar 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)
Expand Down

0 comments on commit 043f6d6

Please sign in to comment.