Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# dbplyr (development version)

* Translations for `as.double()` and `as.character()` with Teradata previously
raised errors and are now correct (@rplsmn, #1545).

* Translations of `difftime()` for Postgres, SQL server, Redshift, and Snowflake
previously returned the wrong sign and are now correct (@edward-burn, #1532).

Expand Down
8 changes: 6 additions & 2 deletions R/backend-teradata.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,12 @@ sql_translation.Teradata <- function(con) {
digits <- vctrs::vec_cast(digits, integer())
sql_expr(CAST(!!x %as% DECIMAL(12L, !!digits)))
},
as.double = sql_cast("NUMERIC"),
as.character = sql_cast("VARCHAR(MAX)"),
as.double = sql_cast("FLOAT"),
as.character = function(x, nchar = 255L) {
check_number_whole(nchar, min = 0, max = 64000)
nchar <- vctrs::vec_cast(nchar, integer())
sql_expr(CAST(!!x %as% VARCHAR(!!nchar)))
},
as.Date = teradata_as_date,
log10 = sql_prefix("LOG"),
log = sql_log(),
Expand Down
5 changes: 3 additions & 2 deletions tests/testthat/test-backend-teradata.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ test_that("custom scalar translated correctly", {
expect_equal(test_translate_sql(x != y), sql("`x` <> `y`"))
expect_equal(test_translate_sql(as.numeric(x)), sql("CAST(`x` AS DECIMAL(12, 9))"))
expect_equal(test_translate_sql(as.numeric(x, 8)), sql("CAST(`x` AS DECIMAL(12, 8))"))
expect_equal(test_translate_sql(as.double(x)), sql("CAST(`x` AS NUMERIC)"))
expect_equal(test_translate_sql(as.character(x)), sql("CAST(`x` AS VARCHAR(MAX))"))
expect_equal(test_translate_sql(as.double(x)), sql("CAST(`x` AS FLOAT)"))
expect_equal(test_translate_sql(as.character(x)), sql("CAST(`x` AS VARCHAR(255))"))
expect_equal(test_translate_sql(as.character(x, 12)), sql("CAST(`x` AS VARCHAR(12))"))
expect_equal(test_translate_sql(log(x)), sql("LN(`x`)"))
expect_equal(test_translate_sql(cot(x)), sql("1 / TAN(`x`)"))
expect_equal(test_translate_sql(nchar(x)), sql("CHARACTER_LENGTH(`x`)"))
Expand Down
Loading