Skip to content

Commit

Permalink
Merge pull request #270 from r-dbi/f-quote-time
Browse files Browse the repository at this point in the history
- `dbQuoteLiteral()` now quotes difftime values as interval (#270).
  • Loading branch information
krlmlr committed Dec 22, 2020
2 parents a7d68c6 + 154b109 commit c3dd048
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion R/PqResult.R
Expand Up @@ -202,7 +202,11 @@ fix_posixt <- function(value) {

difftime_to_hms <- function(value) {
is_difftime <- vlapply(value, inherits, "difftime")
value[is_difftime] <- lapply(value[is_difftime], hms::as_hms)
# https://github.com/tidyverse/hms/issues/84
value[is_difftime] <- lapply(value[is_difftime], function(x) {
mode(x) <- "double"
hms::as_hms(x)
})
value
}

Expand Down
5 changes: 4 additions & 1 deletion R/quote.R
Expand Up @@ -156,7 +156,10 @@ setMethod("dbQuoteLiteral", c("PqConnection", "POSIXt"), function(conn, x, ...)
#' @export
#' @rdname quote
setMethod("dbQuoteLiteral", c("PqConnection", "difftime"), function(conn, x, ...) {
ret <- paste0(as.character(x), "::time")
# https://github.com/tidyverse/hms/issues/84
mode(x) <- "double"

ret <- paste0("'", as.character(hms::as_hms(x)), "'::interval")
ret[is.na(x)] <- "NULL"
SQL(ret, names = names(ret))
})
Expand Down

0 comments on commit c3dd048

Please sign in to comment.