From 8f34aaad2eddf7884acf59297ee945812d7768b2 Mon Sep 17 00:00:00 2001 From: Daniel Possenriede Date: Sat, 22 May 2021 17:10:38 +0200 Subject: [PATCH] make order_by optional in list_table_sql() --- R/PqGenerics.R | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/R/PqGenerics.R b/R/PqGenerics.R index fb1ebc80..5e99ec90 100644 --- a/R/PqGenerics.R +++ b/R/PqGenerics.R @@ -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( @@ -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 } @@ -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, @@ -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,