Skip to content

Commit

Permalink
Revert #1292
Browse files Browse the repository at this point in the history
If ROWNUM is used, we need to wrap it in a subquery, and I don't think that's worth it, given that the version of Oracle that supports FETCH FIRST is now 10 years old.

Fixes #1436
  • Loading branch information
hadley committed Feb 15, 2024
1 parent a662054 commit 3508301
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# dbplyr (development version)

* Oracle once again translates `head()` to `FETCH FIRST`. This does require
Oracle 12c, but it actually works, compared to the approach using `ROWNUM`
from #1292 (#1436).

* The databricks backend now supports creating non-temporary tables too (#1418).

* Clearer error if you attempt to embed non-atomic vectors inside of a generated
Expand Down
10 changes: 5 additions & 5 deletions R/backend-oracle.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ sql_query_select.Oracle <- function(con,
subquery = FALSE,
lvl = 0) {

if (!is.null(limit)) {
limit <- as.integer(limit)
where = c(paste0("ROWNUM <= ", limit), where)
}

sql_select_clauses(con,
select = sql_clause_select(con, select, distinct),
from = sql_clause_from(from),
Expand All @@ -61,6 +56,11 @@ sql_query_select.Oracle <- function(con,
having = sql_clause_having(having),
window = sql_clause_window(window),
order_by = sql_clause_order_by(order_by, subquery, limit),
# Requires Oracle 12c, released in 2013
limit = if (!is.null(limit)) {
limit <- format(as.integer(limit))
glue_sql2(con, "FETCH FIRST {limit} ROWS ONLY")
},
lvl = lvl
)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/backend-oracle.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<SQL>
SELECT `df`.*
FROM `df`
WHERE (ROWNUM <= 6)
FETCH FIRST 6 ROWS ONLY

# `sql_query_upsert()` is correct

Expand Down

0 comments on commit 3508301

Please sign in to comment.