Skip to content

Commit

Permalink
make order_by optional in list_table_sql()
Browse files Browse the repository at this point in the history
  • Loading branch information
dpprdan committed May 22, 2021
1 parent 29f6d29 commit 8f34aaa
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions R/PqGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ setGeneric("pqListTables",
#' @rdname pqListTables
#' @export
setMethod("pqListTables", "PqConnection", function(conn) {
query <- list_tables_sql(conn = conn)
query <- list_tables_sql(conn = conn, order_by = "cl.relkind, cl.relname")

dbGetQuery(conn, query)[["relname"]]
})

list_tables_sql <- function(conn, where_schema = NULL) {
list_tables_sql <- function(conn, where_schema = NULL, order_by = NULL) {
major_server_version <- dbGetInfo(conn)$db.version %/% 10000

query <- paste0(
Expand Down Expand Up @@ -82,10 +82,7 @@ list_tables_sql <- function(conn, where_schema = NULL) {
query <- paste0(query, where_schema)
}

query <- paste0(
query,
"ORDER BY cl.relkind, cl.relname"
)
if (!is.null(order_by)) query <- paste0(query, "ORDER BY ", order_by)

query
}
Expand Down Expand Up @@ -129,7 +126,7 @@ setGeneric("pqListObjects",
setMethod("pqListObjects", c("PqConnection", "ANY"), function(conn, prefix = NULL, ...) {
query <- NULL
if (is.null(prefix)) {
query <- list_tables_sql(conn = conn)
query <- list_tables_sql(conn = conn, order_by = "cl.relkind, cl.relname")
query <- paste0(
"SELECT NULL AS schema, relname AS table FROM ( \n",
query,
Expand All @@ -150,7 +147,12 @@ setMethod("pqListObjects", c("PqConnection", "ANY"), function(conn, prefix = NUL
paste(schema_strings, collapse = ", "),
")"
)
query <- list_tables_sql(conn = conn, where_schema = where_schema)
query <-
list_tables_sql(
conn = conn,
where_schema = where_schema,
order_by = "cl.relkind, cl.relname"
)
query <- paste0(
"SELECT nspname AS schema, relname AS table FROM ( \n",
query,
Expand Down

0 comments on commit 8f34aaa

Please sign in to comment.