diff --git a/R/sql-expr.R b/R/sql-expr.R index ea935367d..45501e6ff 100644 --- a/R/sql-expr.R +++ b/R/sql-expr.R @@ -47,7 +47,9 @@ sql_call2 <- function(.fn, ..., con = sql_current_con()) { replace_expr <- function(x, con) { - if (is.atomic(x) || blob::is_blob(x)) { + if (is.null(x)) { + "NULL" + } else if (is.atomic(x) || blob::is_blob(x)) { as.character(escape(unname(x), con = con)) } else if (is.name(x)) { as.character(x) diff --git a/R/translate-sql-window.R b/R/translate-sql-window.R index 8cf9dc40c..aa01d6b70 100644 --- a/R/translate-sql-window.R +++ b/R/translate-sql-window.R @@ -454,7 +454,7 @@ translate_window_where_all <- function(x, window_funs = common_window_funs()) { } window_where <- function(expr, comp) { - stopifnot(is.call(expr) || is.name(expr) || is.atomic(expr)) + stopifnot(is.call(expr) || is.name(expr) || is.atomic(expr) || is.null(expr)) check_list(comp) list( diff --git a/tests/testthat/test-sql-expr.R b/tests/testthat/test-sql-expr.R index a51657934..88e26a252 100644 --- a/tests/testthat/test-sql-expr.R +++ b/tests/testthat/test-sql-expr.R @@ -1,3 +1,8 @@ +test_that("NULL becomes SQL NULL", { + con <- simulate_dbi() + expect_equal(sql_expr(NULL), sql("NULL")) +}) + test_that("atomic vectors are escaped", { con <- simulate_dbi()