Skip to content

Commit

Permalink
Fix Oracle as.Date() translation, closes #1389
Browse files Browse the repository at this point in the history
  • Loading branch information
mgirlich committed Nov 2, 2023
1 parent bece76c commit 1e2633e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
* Fix translation of `as.integer()` for MySQL (@krlmlr, #1375).
* New `simulate_mariadb()` (@krlmlr, #1375).

* Oracle
* Fix translation of `as.Date()` applied to a string (#1389).

# dbplyr 2.4.0

## Breaking changes
Expand Down
2 changes: 1 addition & 1 deletion R/backend-oracle.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ sql_translation.Oracle <- function(con) {
# https://stackoverflow.com/questions/1171196
as.character = sql_cast("VARCHAR2(255)"),
# https://oracle-base.com/articles/misc/oracle-dates-timestamps-and-intervals
as.Date = function(x) glue_sql2(sql_current_con(), "DATE {x}"),
as.Date = function(x) glue_sql2(sql_current_con(), "DATE {.val x}"),
# bit64::as.integer64 can translate to BIGINT for some
# vendors, which is equivalent to NUMBER(19) in Oracle
# https://docs.oracle.com/cd/B19306_01/gateways.102/b14270/apa.htm
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-backend-oracle.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ test_that("custom scalar functions translated correctly", {
expect_equal(test_translate_sql(as.character(x)), sql("CAST(`x` AS VARCHAR2(255))"))
expect_equal(test_translate_sql(as.integer64(x)), sql("CAST(`x` AS NUMBER(19))"))
expect_equal(test_translate_sql(as.double(x)), sql("CAST(`x` AS NUMBER)"))
expect_equal(test_translate_sql(as.Date(x)), sql("DATE `x`"))
expect_equal(test_translate_sql(as.Date(x)), sql("DATE `x`"))
expect_equal(test_translate_sql(as.Date("2023-01-01")), sql("DATE '2023-01-01'"))
})

test_that("paste and paste0 translate correctly", {
Expand Down

0 comments on commit 1e2633e

Please sign in to comment.