Skip to content
This repository has been archived by the owner on Apr 14, 2018. It is now read-only.

Commit

Permalink
Added as.POSIXct and as.Date scalar functions
Browse files Browse the repository at this point in the history
  • Loading branch information
imanuelcostigan committed Jul 19, 2015
1 parent cca0842 commit 91316c4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 1 addition & 2 deletions R/dbi-shims.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@ db_save_query.SQLServerConnection <- function (con, sql, name, temporary = TRUE,
# http://smallbusiness.chron.com/create-table-query-results-microsoft-sql-50836.html
if (temporary) name <- paste0("#", name)
tt_sql <- dplyr::build_sql("SELECT * INTO ", dplyr::ident(name), " FROM ",
sql_subquery(con, sql), con = con)
dplyr::sql_subquery(con, sql), con = con)
a <- dbSendUpdate(con, tt_sql)
name
}


#' @importFrom dplyr db_drop_table
#' @export
db_drop_table.SQLServerConnection <- function (con, table, force = FALSE, ...) {
Expand Down
7 changes: 6 additions & 1 deletion R/dplyr.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ tbl.src_sqlserver <- function (src, from, ...) {
#' @export
src_translate_env.src_sqlserver <- function (x) {
dplyr::sql_variant(
scalar = dplyr::base_scalar,
scalar = dplyr::sql_translator(.parent = dplyr::base_scalar,
# http://sqlserverplanet.com/tsql/format-string-to-date
as.POSIXct = function(x) build_sql("CAST(", x, " AS DATETIME)"),
# DATE data type only available since SQL Server 2008
as.Date = function (x) build_sql("CAST(", x, " AS DATE)")
),
aggregate = dplyr::sql_translator(.parent = dplyr::base_agg,
n = function() dplyr::sql("COUNT(*)"),
mean = dplyr::sql_prefix('AVG'),
Expand Down

0 comments on commit 91316c4

Please sign in to comment.