-
Notifications
You must be signed in to change notification settings - Fork 63
Closed
Labels
featurea feature request or enhancementa feature request or enhancement
Description
I'm working on a template for a SQL Server MERGE function and want to make the ON statement as dynamic as possible. I do that by building it up one piece at a time. This process involves a glue_collapse() followed by a DBI::SQL() because glue_collapse() coerces to a character(). Should there be a glue_sql_collapse() to support this?
library(glue)
library(odbc)
#> Warning: package 'odbc' was built under R version 3.4.4
library(dbplyr)
#> Warning: package 'dbplyr' was built under R version 3.4.4
x <- c("thing1", "thing2")
y <- c("other1", "other2")
# Mock my S4 sql server connection
setClass("Microsoft SQL Server", representation(quote = "character"), contains = "OdbcConnection")
conn <- new("Microsoft SQL Server", quote = "\"")
sql_conditions <- glue_sql(' "target".{`x`} = "source".{`y`} ', .con = conn)
sql_conditions
#> <SQL> "target"."thing1" = "source"."other1"
#> <SQL> "target"."thing2" = "source"."other2"
# Can't just use glue_collapse(). Get back a character.
sql_combined_conditions <- DBI::SQL(glue::glue_collapse(sql_conditions, sep = " AND "))
sql_combined_conditions
#> <SQL> "target"."thing1" = "source"."other1" AND "target"."thing2" = "source"."other2"
sql_ON <- glue::glue_sql("ON {sql_combined_conditions}", .con = conn)
sql_ON
#> <SQL> ON "target"."thing1" = "source"."other1" AND "target"."thing2" = "source"."other2"Created on 2018-07-31 by the reprex package (v0.2.0).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
featurea feature request or enhancementa feature request or enhancement