Skip to content

Commit 8f34aaa

Browse files
committed
make order_by optional in list_table_sql()
1 parent 29f6d29 commit 8f34aaa

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

R/PqGenerics.R

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ setGeneric("pqListTables",
3333
#' @rdname pqListTables
3434
#' @export
3535
setMethod("pqListTables", "PqConnection", function(conn) {
36-
query <- list_tables_sql(conn = conn)
36+
query <- list_tables_sql(conn = conn, order_by = "cl.relkind, cl.relname")
3737

3838
dbGetQuery(conn, query)[["relname"]]
3939
})
4040

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

4444
query <- paste0(
@@ -82,10 +82,7 @@ list_tables_sql <- function(conn, where_schema = NULL) {
8282
query <- paste0(query, where_schema)
8383
}
8484

85-
query <- paste0(
86-
query,
87-
"ORDER BY cl.relkind, cl.relname"
88-
)
85+
if (!is.null(order_by)) query <- paste0(query, "ORDER BY ", order_by)
8986

9087
query
9188
}
@@ -129,7 +126,7 @@ setGeneric("pqListObjects",
129126
setMethod("pqListObjects", c("PqConnection", "ANY"), function(conn, prefix = NULL, ...) {
130127
query <- NULL
131128
if (is.null(prefix)) {
132-
query <- list_tables_sql(conn = conn)
129+
query <- list_tables_sql(conn = conn, order_by = "cl.relkind, cl.relname")
133130
query <- paste0(
134131
"SELECT NULL AS schema, relname AS table FROM ( \n",
135132
query,
@@ -150,7 +147,12 @@ setMethod("pqListObjects", c("PqConnection", "ANY"), function(conn, prefix = NUL
150147
paste(schema_strings, collapse = ", "),
151148
")"
152149
)
153-
query <- list_tables_sql(conn = conn, where_schema = where_schema)
150+
query <-
151+
list_tables_sql(
152+
conn = conn,
153+
where_schema = where_schema,
154+
order_by = "cl.relkind, cl.relname"
155+
)
154156
query <- paste0(
155157
"SELECT nspname AS schema, relname AS table FROM ( \n",
156158
query,

0 commit comments

Comments
 (0)