diff --git a/.Rbuildignore b/.Rbuildignore index 56713387..ae495631 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,8 +1,19 @@ +extras +license_header_stub.txt +pom.xml ^.*\.Rproj$ ^\.Rproj\.user$ .travis.yml .classpath .project -build +^cran-comments.md$ build.xml deploy.sh +extras/ +pom.xml +bin/ +.idea/ +SqlRender.iml +license_header_stub.txt +target/ +docs diff --git a/.classpath b/.classpath index cb0e57e8..48775fc5 100644 --- a/.classpath +++ b/.classpath @@ -1,6 +1,6 @@ - + diff --git a/.travis.yml b/.travis.yml index ca8f01f9..e6b0319e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,71 +1,24 @@ -# .travis.yml using container-based infrastructure -# from: https://github.com/jtilly/R-travis-container-example/blob/master/.travis.yml - -language: c - -# use containers +language: R +cache: packages sudo: false -# install R: use r-packages-precise (https://cran.r-project.org/bin/linux/ubuntu/precise/) -# as source which is white listed (https://github.com/travis-ci/apt-source-whitelist/) -addons: - apt: - sources: - - r-packages-precise - packages: - - r-base-dev - - r-recommended - - pandoc - - default-jdk - - default-jre - -# cache local R libraries directory: -cache: - directories: - - ~/Rlib - -# install the package and dependencies: -install: - - mkdir -p ~/Rlib - - echo 'R_LIBS=~/Rlib' > .Renviron - - echo 'options(repos = "http://cran.rstudio.com")' > .Rprofile - - mkdir -p ~/.R - - Rscript -e 'if(!"devtools" %in% rownames(installed.packages())) { install.packages("devtools", dependencies = TRUE) }' - - Rscript -e 'if (!require("covr")) devtools::install_github("jimhester/covr")' - - Rscript -e 'if (!require("drat")) install.packages("drat")' - - Rscript -e 'if(!"rJava" %in% rownames(installed.packages())) { install.packages("rJava", dependencies = TRUE) }' - - Rscript -e 'if(!"testthat" %in% rownames(installed.packages())) { install.packages("testthat", dependencies = TRUE) }' - - Rscript -e 'if(!"knitr" %in% rownames(installed.packages())) { install.packages("knitr", dependencies = TRUE) }' - - Rscript -e 'if(!"rmarkdown" %in% rownames(installed.packages())) { install.packages("rmarkdown", dependencies = TRUE) }' - - Rscript -e 'update.packages(ask = FALSE, instlib = "~/Rlib")' - - Rscript -e 'devtools::install_deps(pkg = ".", dependencies = TRUE)' - -before_script: - - export PKG_NAME=$(Rscript -e 'cat(paste0(devtools::as.package(".")$package))') - - export PKG_TARBALL=$(Rscript -e 'pkg <- devtools::as.package("."); cat(paste0(pkg$package,"_",pkg$version,".tar.gz"))') +r_packages: + - covr + - drat -# Build and check package -script: - - R CMD build . --no-build-vignettes --no-manual - - PKG_FILE_NAME=$(ls -1t *.tar.gz | head -n 1) - - PKG_NAME=$(ls -1t *.tar.gz | head -n 1 | sed 's/_.*gz//') - - _R_CHECK_CRAN_INCOMING_=FALSE R CMD check "${PKG_FILE_NAME}" --no-build-vignettes --no-manual - - cat ${PKG_NAME}.Rcheck/00install.out # Print out install / compile log +before_install: + - Rscript -e 'update.packages(ask = FALSE)' + - export LD_LIBRARY_PATH=$JAVA_HOME:$LD_LIBRARY_PATH notifications: recipients: - - msuchard@gmail.com - - schuemie@ohdsi.org + - msuchard@gmail.com + - schuemie@ohdsi.org email: on_success: change on_failure: change after_success: - - Rscript -e 'library(covr);codecov()' - # Rebuild docker container - - curl --data "build=true" -X POST https://registry.hub.docker.com/u/ohdsi/development/trigger/e51f720d-c4e7-45df-b042-5d8a362bd7e0/ + - Rscript -e 'covr::codecov()' + - curl --data "build=true" -X POST https://registry.hub.docker.com/u/ohdsi/broadsea-methodslibrary/trigger/f0b51cec-4027-4781-9383-4b38b42dd4f5/ - test $TRAVIS_PULL_REQUEST == "false" && test $TRAVIS_BRANCH == "master" && bash deploy.sh - -env: - global: - secure: eUCnclALTsNc8+oOVS8qeSkD8CcYwAPfq759YG/WYXHpTgWDtjCAeHBARWmELHxkGDromzT+lNL3gnbs0WfqD+Nm0prAO7tjPIVKRe4h8zDHwLgZyPQSv17YwwNQZknEPWDrP18BpGqrKCDl8qYsL80+6QVqBs1FczZI7taSfB0= diff --git a/DESCRIPTION b/DESCRIPTION index 699ed3b1..64daafd6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,19 +1,28 @@ Package: SqlRender Type: Package Title: Rendering Parameterized SQL and Translation to Dialects -Version: 1.1.4 -Date: 2016-05-30 -Author: Martijn J. Schuemie and Marc A. Suchard +Version: 1.4.3 +Date: 2017-06-09 +Authors@R: c( + person("Martijn", "Schuemie", , "schuemie@ohdsi.org", role = c("aut", "cre")), + person("Marc", "Suchard", role = c("aut")) + ) Maintainer: Martijn Schuemie -Description: This is an R package for rendering parameterized SQL, and - translating it to different SQL dialects. -License: Apache License +Description: A rendering tool for parameterized SQL that also translates into + different SQL dialects. These dialects include Sql Server, Oracle, + PostgreSql, Amazon RedShift, Impala, IBM Netezza, Google BigQuery, and Microsoft PDW. +License: Apache License 2.0 VignetteBuilder: knitr +URL: https://github.com/OHDSI/SqlRender +BugReports: https://github.com/OHDSI/SqlRender/issues Imports: rJava Suggests: testthat, knitr, - rmarkdown + rmarkdown, + shiny, + shinydashboard, + formatR LazyData: false -RoxygenNote: 5.0.1 +RoxygenNote: 6.0.1 diff --git a/NAMESPACE b/NAMESPACE index e9813994..cf33e6fc 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,6 +2,7 @@ export(camelCaseToSnakeCase) export(createRWrapperForSql) +export(launchSqlRenderDeveloper) export(loadRenderTranslateSql) export(readSql) export(renderSql) @@ -12,3 +13,5 @@ export(translateSql) export(translateSqlFile) export(writeSql) import(rJava) +importFrom(utils,install.packages) +importFrom(utils,menu) diff --git a/NEWS b/NEWS new file mode 100644 index 00000000..ef32b204 --- /dev/null +++ b/NEWS @@ -0,0 +1,52 @@ +SqlRender v1.3.7 (Release date: 2017-05-03) +=========================================== + +Changes: + +1. Added translation rules for ISNUMERIC and LOG(@expression, @base) + + +Bugfixes: + +1. Fixed bug when trying to split SQL where reserved word 'end' is used as a field name. +2. Fixes for Impala translations. +3. Fixed translation issues for Oracle involving 'FROM DUAL'. +4. Added workaround for Oracle bug for intervals greater than 99 days. +5. Fixed bug when trying to split SQL where last line has comment but no EOL. + + +SqlRender v1.3.0 (Release date: 2017-03-24) +=========================================== + +Changes: + +1. Added ability to use regular expression in translation patterns. This allowed SELECT TOP n to be translated. +2. Deprecated sourceDialect argument. +3. Added translation for CONCAT function with >2 arguments to Oracle (which only allows 2 arguments) +4. Added hints for translation optimation to massive parallel platforms like RedShift +5. Throw warnings when translateSql is called with variable names that are not in the SQL +6. Throw warnings when table names are too long for Oracle + + +Bugfixes: + +1. Fixed translation for date functions so they will now work properly with datetime fields as well. +2. Now throwing error when boolean logic cannot be parsed (instead of assuming result is TRUE) + + +SqlRender v1.2.0 (Release date: 2017-01-12) +=========================================== + +Changes: + +1. Added support for Impala + +Bugfixes: + +1. Fixed translation for DATEFROMPARTS for RedShift + + +SqlRender v1.1.7 (Release date: 2016-08-15) +=========================================== + +Changes: initial submission to CRAN diff --git a/R/HelperFunctions.R b/R/HelperFunctions.R index 043f1557..fa452541 100644 --- a/R/HelperFunctions.R +++ b/R/HelperFunctions.R @@ -1,6 +1,6 @@ # @file HelperFunctions.R # -# Copyright 2016 Observational Health Data Sciences and Informatics +# Copyright 2017 Observational Health Data Sciences and Informatics # # This file is part of SqlRender # @@ -109,7 +109,7 @@ renderSqlFile <- function(sourceFile, targetFile, ...) { #' #' @param sourceFile The source SQL file #' @param targetFile The target SQL file -#' @param sourceDialect The source dialect. Currently, only 'sql server' for Microsoft SQL Server +#' @param sourceDialect Deprecated: The source dialect. Currently, only 'sql server' for Microsoft SQL Server #' is supported #' @param targetDialect The target dialect. Currently 'oracle', 'postgresql', and 'redshift' are #' supported @@ -124,11 +124,14 @@ renderSqlFile <- function(sourceFile, targetFile, ...) { #' @export translateSqlFile <- function(sourceFile, targetFile, - sourceDialect = "sql server", - targetDialect = "oracle", + sourceDialect, + targetDialect, oracleTempSchema = NULL) { + if (!missing(sourceDialect)) + warning("sourceDialect argument is deprecated in the translateSqlFile function in SqlRender. Please update your code") + sql <- readSql(sourceFile) - sql <- translateSql(sql, sourceDialect, targetDialect, oracleTempSchema = oracleTempSchema)$sql + sql <- translateSql(sql = sql, targetDialect = targetDialect, oracleTempSchema = oracleTempSchema)$sql writeSql(sql, targetFile) } @@ -179,12 +182,12 @@ loadRenderTranslateSql <- function(sqlFilename, package = packageName) } parameterizedSql <- readChar(pathToSql, file.info(pathToSql)$size) - + renderedSql <- renderSql(parameterizedSql[1], ...)$sql - + if (mustTranslate) - renderedSql <- translateSql(renderedSql, "sql server", dbms, oracleTempSchema)$sql - + renderedSql <- translateSql(sql = renderedSql, targetDialect = dbms, oracleTempSchema = oracleTempSchema)$sql + renderedSql } @@ -212,7 +215,7 @@ snakeCaseToCamelCase <- function(string) { for (number in 0:9) { string <- gsub(paste("_", number, sep = ""), number, string) } - + string } @@ -273,7 +276,7 @@ createRWrapperForSql <- function(sqlFilename, rFilename <- paste(substr(sqlFilename, 1, periodIndex), "R", sep = "") } } - + pathToSql <- system.file(paste("sql/", "sql_server", sep = ""), sqlFilename, package = packageName) @@ -287,7 +290,7 @@ createRWrapperForSql <- function(sqlFilename, } else { stop("Could not find SQL file") } - + hasTempTables <- any(gregexpr("\\#", parameterizedSql)[[1]] != -1) hits <- gregexpr("\\{DEFAULT @[^}]*\\}", parameterizedSql) hits <- cbind(hits[[1]], attr(hits[[1]], "match.length")) @@ -315,10 +318,10 @@ createRWrapperForSql <- function(sqlFilename, if (any(definitions[, 1] == databaseParameter)) databaseParameters <- rbind(databaseParameters, definitions[definitions$sqlParameter == databaseParameter, - ]) + ]) } functionDefinitions <- definitions[!(definitions$sqlParameter %in% databaseParameters$sqlParameter), ] - + lines <- c() if (createRoxygenTemplate) { lines <- c(lines, "#' Todo: add title") @@ -347,12 +350,12 @@ createRWrapperForSql <- function(sqlFilename, for (i in 1:nrow(functionDefinitions)) { if (i == nrow(functionDefinitions)) end <- ") {" else end <- "," - lines <- c(lines, paste(" ", - functionDefinitions$rParameter[i], - " = ", - functionDefinitions$value[i], - end, - sep = "")) + lines <- c(lines, paste(" ", + functionDefinitions$rParameter[i], + " = ", + functionDefinitions$value[i], + end, + sep = "")) } for (databaseParameter in databaseParameters$rParameter) { lines <- c(lines, paste(" ", @@ -364,7 +367,7 @@ createRWrapperForSql <- function(sqlFilename, } lines <- c(lines, paste(" renderedSql <- SqlRender::loadRenderTranslateSql(\"", sqlFilename, "\",", - sep = "")) + sep = "")) lines <- c(lines, paste(" packageName = \"", packageName, "\",", sep = "")) lines <- c(lines, " dbms = connectionDetails$dbms,") if (hasTempTables) @@ -372,12 +375,12 @@ createRWrapperForSql <- function(sqlFilename, for (i in 1:nrow(definitions)) { if (i == nrow(definitions)) end <- ")" else end <- "," - lines <- c(lines, paste(" ", - definitions$sqlParameter[i], - " = ", - definitions$rParameter[i], - end, - sep = "")) + lines <- c(lines, paste(" ", + definitions$sqlParameter[i], + " = ", + definitions$rParameter[i], + end, + sep = "")) } lines <- c(lines, " conn <- DatabaseConnector::connect(connectionDetails)") lines <- c(lines, "") diff --git a/R/RenderSql.R b/R/RenderSql.R index bed134d8..342f29d6 100644 --- a/R/RenderSql.R +++ b/R/RenderSql.R @@ -1,6 +1,6 @@ # @file RenderSql # -# Copyright 2016 Observational Health Data Sciences and Informatics +# Copyright 2017 Observational Health Data Sciences and Informatics # # This file is part of SqlRender # @@ -20,6 +20,13 @@ # @author Martijn Schuemie # @author Marc Suchard +#' SqlRender +#' +#' @docType package +#' @name SqlRender +#' @importFrom utils install.packages menu +NULL + .onLoad <- function(libname, pkgname) { rJava::.jpackage(pkgname, lib.loc = libname) } @@ -64,6 +71,10 @@ renderSql <- function(sql = "", ...) { parameters <- lapply(list(...), function(x) { paste(x, collapse = ",") }) + messages <- rJava::J("org.ohdsi.sql.SqlRender")$check(sql, rJava::.jarray(names(parameters)), rJava::.jarray(as.character(parameters))) + for (message in messages) { + warning(message) + } translatedSql <- rJava::J("org.ohdsi.sql.SqlRender")$renderSql(sql, rJava::.jarray(names(parameters)), rJava::.jarray(as.character(parameters))) list(originalSql = sql, sql = translatedSql, parameters = parameters) } @@ -80,27 +91,32 @@ renderSql <- function(sql = "", ...) { #' replacement, so its functionality is limited. #' #' @param sql The SQL to be translated -#' @param sourceDialect The source dialect. Currently, only "sql server" for Microsoft SQL Server +#' @param sourceDialect Deprecated: The source dialect. Currently, only "sql server" for Microsoft SQL Server #' is supported -#' @param targetDialect The target dialect. Currently "oracle", "postgresql", "pdw", and +#' @param targetDialect The target dialect. Currently "oracle", "postgresql", "pdw", "impala", "netezza", "bigquery", and #' "redshift" are supported -#' @param oracleTempSchema A schema that can be used to create temp tables in when using Oracle. +#' @param oracleTempSchema A schema that can be used to create temp tables in when using Oracle or Impala. #' @return #' A list containing the following elements: \describe{ \item{originalSql}{The original parameterized #' SQL code} \item{sql}{The translated SQL} } #' @examples -#' \dontrun{ -#' translateSql("USE my_schema", "sql server", "oracle") -#' } +#' translateSql("USE my_schema;", targetDialect = "oracle") +#' #' @export translateSql <- function(sql = "", - sourceDialect = "sql server", - targetDialect = "oracle", - oracleTempSchema = NULL) { + targetDialect, + oracleTempSchema = NULL, + sourceDialect) { + if (!missing(sourceDialect)) + warning("sourceDialect argument is deprecated in the translateSql function in SqlRender. Please update your code") pathToReplacementPatterns <- system.file("csv", "replacementPatterns.csv", package = "SqlRender") if (missing(oracleTempSchema) || is.null(oracleTempSchema)) oracleTempSchema <- rJava::.jnull() - translatedSql <- rJava::J("org.ohdsi.sql.SqlTranslate")$translateSql(sql, sourceDialect, targetDialect, rJava::.jnull(), oracleTempSchema, pathToReplacementPatterns) + messages <- rJava::J("org.ohdsi.sql.SqlTranslate")$check(sql, targetDialect) + for (message in messages) { + warning(message) + } + translatedSql <- rJava::J("org.ohdsi.sql.SqlTranslate")$translateSqlWithPath(sql, targetDialect, rJava::.jnull(), oracleTempSchema, pathToReplacementPatterns) list(originalSql = sql, sql = translatedSql) } diff --git a/R/ShinyApps.R b/R/ShinyApps.R new file mode 100644 index 00000000..109573c8 --- /dev/null +++ b/R/ShinyApps.R @@ -0,0 +1,54 @@ +# Copyright 2017 Observational Health Data Sciences and Informatics +# +# This file is part of SqlRender +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#' Launch the SqlRender Developer Shiny app +#' +#' @param launch.browser Should the app be launched in your default browser, or in a Shiny window. +#' Note: copying to clipboard will not work in a Shiny window. +#' +#' @details +#' Launches a Shiny app that allows the user to develop SQL and see how it translates to the supported dialects. +#' +#' @export +launchSqlRenderDeveloper <- function(launch.browser = TRUE) { + ensure_installed("shinydashboard") + appDir <- system.file("shinyApps", "SqlDeveloper", package = "SqlRender") + shiny::runApp(appDir, display.mode = "normal", launch.browser = launch.browser) +} + +# Borrowed from devtools: https://github.com/hadley/devtools/blob/ba7a5a4abd8258c52cb156e7b26bb4bf47a79f0b/R/utils.r#L44 +is_installed <- function (pkg, version = 0) { + installed_version <- tryCatch(utils::packageVersion(pkg), + error = function(e) NA) + !is.na(installed_version) && installed_version >= version +} + +# Borrowed and adapted from devtools: https://github.com/hadley/devtools/blob/ba7a5a4abd8258c52cb156e7b26bb4bf47a79f0b/R/utils.r#L74 +ensure_installed <- function(pkg) { + if (!is_installed(pkg)) { + msg <- paste0(sQuote(pkg), " must be installed for this functionality.") + if (interactive()) { + message(msg, "\nWould you like to install it?") + if (menu(c("Yes", "No")) == 1) { + install.packages(pkg) + } else { + stop(msg, call. = FALSE) + } + } else { + stop(msg, call. = FALSE) + } + } +} \ No newline at end of file diff --git a/README.md b/README.md index 2a8581e4..b0d013e8 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,19 @@ SqlRender ========= +[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/SqlRender)](https://cran.r-project.org/package=SqlRender) + Introduction ============ -This is an R package for rendering parameterized SQL, and translating it to different SQL dialects. SqlRender can also be used as a stand-alone Java library. +This is an R package for rendering parameterized SQL, and translating it to different SQL dialects. SqlRender can also be used as a stand-alone Java library and a command-line executable. Features ======== - Supports a simple markup syntax for making SQL parameterized, and renders parameterized SQL (containing the markup syntax) to executable SQL - The syntax supports defining default parameter values - The syntax supports if-then-else structures -- Has functions for translating SQL from one dialect (Microsoft SQL Server) to other dialects (Oracle, PostgreSQL, Amazon RedShift) +- Has functions for translating SQL from one dialect (Microsoft SQL Server) to other dialects (Oracle, PostgreSQL, Amazon RedShift, Impala, IBM Netezza, Google BigQuery, and Microsoft PDW) +- Can be used as R package, Java library, or as stand-alone executable through a command-line interface Examples ======== @@ -56,14 +59,27 @@ Getting Started =============== ## R package -Use these commands in R to download and install the SqlRender package: +In R, use the following commands to install the latest stable version from CRAN: + +```r +install.packages("SqlRender") +``` + +To install the latest development version directly from GitHub, use: ```r install.packages("devtools") -library("devtools") +library(devtools) install_github("ohdsi/SqlRender") ``` +Once installed, you can try out SqlRender in a Shiny app that comes with the package: + +```r +library(SqlRender) +launchSqlRenderDeveloper() +``` + ## Java library You can fetch the JAR file in the inst/java folder of this repository, or use Maven: @@ -97,10 +113,16 @@ You can fetch the JAR file in the inst/java folder of this repository, or use Ma ``` +## Command-line executable +You can fetch the JAR file in the inst/java folder of this repository, or use Maven as described above. Run this from the command line to get a list of options: +``` +java -jar SqlRender.jar ? +``` + Getting Involved ============= -* Vignette: [Using SqlRender](https://raw.githubusercontent.com/OHDSI/SqlRender/master/inst/doc/UsingSqlRender.pdf) -* Package manual: [SqlRender manual](https://raw.githubusercontent.com/OHDSI/SqlRender/master/extras/SqlRender.pdf) +* Vignette: [Using SqlRender](http://ohdsi.github.io/SqlRender/articles/UsingSqlRender.html) +* Package manual: [SqlRender manual](http://ohdsi.github.io/SqlRender/reference/index.html) * Developer questions/comments/feedback: OHDSI Forum * We use the GitHub issue tracker for all bugs/issues/enhancements @@ -112,7 +134,7 @@ Development =========== SqlRender is being developed in R Studio. -###Development status +### Development status [![Build Status](https://travis-ci.org/OHDSI/SqlRender.svg?branch=master)](https://travis-ci.org/OHDSI/SqlRender) [![codecov.io](https://codecov.io/github/OHDSI/SqlRender/coverage.svg?branch=master)](https://codecov.io/github/OHDSI/SqlRender?branch=master) diff --git a/SqlRender.Rproj b/SqlRender.Rproj index 3e61e222..27a9ed9f 100644 --- a/SqlRender.Rproj +++ b/SqlRender.Rproj @@ -13,5 +13,6 @@ RnwWeave: knitr LaTeX: pdfLaTeX BuildType: Package -PackageInstallArgs: --no-multiarch --with-keep.source +PackageInstallArgs: --with-keep.source +PackageCheckArgs: --as-cran PackageRoxygenize: rd,collate,namespace diff --git a/build.xml b/build.xml deleted file mode 100644 index ab8befca..00000000 --- a/build.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - Simple build fine for SqlRender.jar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/cran-comments.md b/cran-comments.md new file mode 100644 index 00000000..4dcda227 --- /dev/null +++ b/cran-comments.md @@ -0,0 +1,15 @@ +This update has five bugfixes and adds some new translation rules (see NEWS) + +--- + +## Test environments +* Ubuntu 12.04.5 LTS (Travis), R 3.2.5 +* Windows 7, R 3.4.0 + +## R CMD check results + +There were no ERRORs or WARNINGs. + +## Downstream dependencies + +There are no downstream dependencies. \ No newline at end of file diff --git a/docs/articles/UsingSqlRender.html b/docs/articles/UsingSqlRender.html new file mode 100644 index 00000000..5ffd2694 --- /dev/null +++ b/docs/articles/UsingSqlRender.html @@ -0,0 +1,476 @@ + + + + + + + +Using SqlRender • SqlRender + + + + + + +
+
+ + + +
+
+ + + + +
+
+

+Introduction

+

This vignette describes how one could use the SqlRender R package.

+
+
+

+SQL parameterization

+

One of the main functions of the package is to support parameterization of SQL. Often, small variations of SQL need to be generated based on some parameters. SqlRender offers a simple markup syntax inside the SQL code to allow parameterization. Rendering the SQL based on parameter values is done using the renderSql() function.

+
+

+Substituting parameter values

+

The @ character can be used to indicate parameter names that need to be exchange for actual parameter values when rendering. In the following example, a variable called a is mentioned in the SQL. In the call to the renderSql function the value of this parameter is defined:

+
sql <- "SELECT * FROM table WHERE id = @a;"
+renderSql(sql, a = 123)$sql
+
#> [1] "SELECT * FROM table WHERE id = 123;"
+

Note that, unlike the parameterization offered by most database management systems, it is just as easy to parameterize table or field names as values:

+
sql <- "SELECT * FROM @x WHERE id = @a;"
+renderSql(sql, x = "my_table", a = 123)$sql
+
#> [1] "SELECT * FROM my_table WHERE id = 123;"
+

The parameter values can be numbers, strings, booleans, as well as vectors, which are converted to comma-delimited lists:

+
sql <- "SELECT * FROM table WHERE id IN (@a);"
+renderSql(sql, a = c(1, 2, 3))$sql
+
#> [1] "SELECT * FROM table WHERE id IN (1,2,3);"
+
+
+

+Default parameter values

+

For some or all parameters, it might make sense to define default values that will be used unless the user specifies another value. This can be done using the {DEFAULT @parameter = value} syntax:

+
sql <- "{DEFAULT @a = 1} SELECT * FROM table WHERE id = @a;"
+renderSql(sql)$sql
+
#> [1] "SELECT * FROM table WHERE id = 1;"
+
renderSql(sql, a = 2)$sql
+
#> [1] "SELECT * FROM table WHERE id = 2;"
+

Defaults for multiple variables can be defined:

+
sql <- "{DEFAULT @a = 1} {DEFAULT @x = 'my_table'} SELECT * FROM @x WHERE id = @a;"
+renderSql(sql)$sql
+
#> [1] "SELECT * FROM my_table WHERE id = 1;"
+
+
+

+If-then-else

+

Sometimes blocks of codes need to be turned on or off based on the values of one or more parameters. This is done using the {Condition} ? {if true} : {if false} syntax. If the condition evaluates to true or 1, the if true block is used, else the if false block is shown (if present).

+
sql <- "SELECT * FROM table {@x} ? {WHERE id = 1}"
+renderSql(sql, x = FALSE)$sql
+
#> [1] "SELECT * FROM table "
+
renderSql(sql, x = TRUE)$sql
+
#> [1] "SELECT * FROM table WHERE id = 1"
+

Simple comparisons are also supported:

+
sql <- "SELECT * FROM table {@x == 1} ? {WHERE id = 1};"
+renderSql(sql, x = 1)$sql
+
#> [1] "SELECT * FROM table WHERE id = 1;"
+
renderSql(sql, x = 2)$sql
+
#> [1] "SELECT * FROM table ;"
+

As well as the IN operator:

+
sql <- "SELECT * FROM table {@x IN (1,2,3)} ? {WHERE id = 1}; "
+renderSql(sql, x = 2)$sql
+
#> [1] "SELECT * FROM table WHERE id = 1; "
+
+
+
+

+Translation to other SQL dialects

+

SQL for one platform (e.g. Microsoft SQL Server) will not always execute on other platforms (e.g. Oracle). The translateSql() function can be used to translate between different dialects, but there are some limitations.

+

A first limitation is that the starting dialect has to be SQL Server. The reason for this is that this dialect is in general the most specific. For example, the number of days between two dates in SQL Server has to be computed using the DATEDIFF function: DATEDIFF(dd,a,b). In other languages one can simply subtract the two dates: b-a. Since you’d need to know a and b are dates, it is not possible to go from other languages to SQL Server, only the other way around.

+

A second limitation is that currently only these dialects are supported as targets: Oracle, PostgreSQL, Microsoft PDW (Parallel Data Warehouse), Impala, Netezza, Google BigQuery, and Amazon Redhift.

+

A third limitation is that only a limited set of translation rules have currently been implemented, although adding them to the list should not be hard.

+

A last limitation is that not all functions supported in one dialect have an equivalent in other dialects.

+

Below an example:

+
sql <- "SELECT DATEDIFF(dd,a,b) FROM table; "
+translateSql(sql, targetDialect = "oracle")$sql
+
#> [1] "SELECT (CAST(b AS DATE) - CAST(a AS DATE))  FROM table ; "
+

The targetDialect parameter can have the following values:

+
    +
  • “oracle”
  • +
  • “postgresql”
  • +
  • “pdw”
  • +
  • “redshift”
  • +
  • “impala”
  • +
  • “netezza”
  • +
  • “bigquery”
  • +
  • “sql server” (no translation)
  • +
+
+

+Functions and structures supported by translateSql

+

These SQL Server functions have been tested and were found to be translated correctly to the various dialects:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Functions supported by translateSql
FunctionFunctionFunctionFunction
ABSDATEDIFFLOGROUND
ACOSDATEFROMPARTSLOG10ROW_NUMBER
ASINDATETIMEFROMPARTSLOWERRTRIM
ATANDAYLTRIMSIN
AVGEOMONTHMAXSQRT
CASTEXPMINSQUARE
CEILINGFLOORMONTHSTDEV
CHARINDEXGETDATENEWIDSUM
CONCATHASHBYTES*PITAN
COSISNULLPOWERUPPER
COUNTISNUMERICRANDVAR
COUNT_BIGLEFTRANKYEAR
DATEADDLENRIGHT
+
    +
  • Requires special priviliges on Oracle
  • +
+

Similarly, many SQL syntax structures are supported. Here is a non-exhaustive lists of things that we know will translate well:

+
SELECT * FROM table;                                        -- Simple selects
+
+SELECT * FROM table_1 INNER JOIN table_2 ON a = b;          -- Selects with joins 
+
+SELECT * FROM (SELECT * FROM table_1) tmp WHERE a = b;      -- Nested queries
+
+SELECT TOP 10 * FROM table;                                 -- Limiting to top rows
+
+SELECT * INTO new_table FROM table;                         -- Selecting into a new table
+
+CREATE TABLE table (field INT);                             -- Creating tables
+
+INSERT INTO other_table (field_1) VALUES (1);               -- Inserting verbatim values           
+
+INSERT INTO other_table (field_1) SELECT value FROM table;  -- Inserting from SELECT
+  
+DROP TABLE table;                                           -- Simple drop commands
+
+IF OBJECT_ID('ACHILLES_analysis', 'U') IS NOT NULL          -- Drop table if it exists
+  DROP TABLE ACHILLES_analysis;
+  
+IF OBJECT_ID('tempdb..#cohorts', 'U') IS NOT NULL           -- Drop temp table if it exists
+  DROP TABLE #cohorts;  
+
+WITH cte AS (SELECT * FROM table) SELECT * FROM cte;        -- Common table expressions
+
+SELECT ROW_NUMBER() OVER (PARTITION BY a ORDER BY b)        -- OVER clauses
+  AS "Row Number" FROM table;
+  
+SELECT CASE WHEN a=1 THEN a ELSE 0 END AS value FROM table; -- CASE WHEN clauses
+
+SELECT * FROM a UNION SELECT * FROM b                       -- UNIONs
+
+SELECT * FROM a INTERSECT SELECT * FROM b                   -- INTERSECTIONs
+
+SELECT * FROM a EXCEPT SELECT * FROM b                      -- EXCEPT
+
+
+

+String concatenation

+

String concatenation is one area where SQL Server is less specific than other dialects. In SQL Server, one would write SELECT first_name + ' ' + last_name AS full_name FROM table, but this should be SELECT first_name || ' ' || last_name AS full_name FROM table in PostgreSQL and Oracle. SqlRender tries to guess when values that are being concatenated are strings. In the example above, because we have an explicit string (the space surrounded by single quotation marks), the translation will be correct. However, if the query had been SELECT first_name + last_name AS full_name FROM table, SqlRender would have had no clue the two fields were strings, and would incorrectly leave the plus sign. Another clue that a value is a string is an explicit cast to VARCHAR, so SELECT last_name + CAST(age AS VARCHAR(3)) AS full_name FROM table would also be translated correctly. To avoid ambiguity altogether, it is probable best to use the CONCAT() function to concatenate two or more strings.

+
+
+

+Temp tables

+

Temp tables can be very useful to store intermediate results, and when used correctly can be used to dramatically improve performance of queries. In Postgres, PDW, RedShift and SQL Server temp tables have very nice properties: they’re only visible to the current user, are automatically dropped when the session ends, and can be created even when the user has no write access. Unfortunately, in Oracle temp tables are basically permanent tables, with the only difference that the data inside the table is only visible to the current user. This is why, in Oracle, SqlRender will try to emulate temp tables by

+
    +
  1. Adding a random string to the table name so tables from different users will not conflict.
  2. +
  3. Allowing the user to specify the schema where the temp tables will be created.
  4. +
+

For example:

+
sql <- "SELECT * FROM #children;"
+translateSql(sql, targetDialect = "oracle", oracleTempSchema = "temp_schema")$sql
+
#> [1] "SELECT *  FROM temp_schema.kp8f8g5fchildren ;"
+

Note that the user will need to have write privileges on temp_schema.

+

Also note that because Oracle has a limit on table names of 30 characters, temp table names are only allowed to be at most 22 characters long because else the name will become too long after appending the session ID.

+

Futhermore, remember that temp tables are not automatically dropped on Oracle, so you will need to explicitly TRUNCATE and DROP all temp tables once you’re done with them to prevent orphan tables accumulating in the Oracle temp schema.

+

If possible, try to avoid using temp tables altogether. Sometimes one could use Common Table Expressions (CTEs) when one would normally use a temp table. For example, instead of

+
SELECT * INTO #children FROM person WHERE year_of_birth > 2000;
+SELECT * FROM #children WHERE gender = 8507;
+

you could use

+
WITH children AS (SELECT * FROM person WHERE year_of_birth > 2000)
+SELECT * FROM children WHERE gender = 8507;
+
+
+

+Implicit casts

+

One of the few points where SQL Server is less explicit than other dialects is that it allows implicit casts. For example, this code will work on SQL Server:

+
CREATE TABLE #temp (txt VARCHAR);
+
+INSERT INTO #temp
+SELECT '1';
+
+SELECT * FROM #temp WHERE txt = 1;
+

Even though txt is a VARCHAR field and we are comparing it with an integer, SQL Server will automatically cast one of the two to the correct type to allow the comparison. In contrast, other dialects such as PosgreSQL will throw an error when trying to compare a VARCHAR with an INT.

+

You should therefore always make casts explicit. In the above example, the last statement should be replaced with either

+
SELECT * FROM #temp WHERE txt = CAST(1 AS VARCHAR);
+

or

+
SELECT * FROM #temp WHERE CAST(txt AS INT) = 1;
+
+
+

+Case sensitivity in string comparisons

+

Some DBMS platforms such as SQL Server always perform string comparisons in a case-insensitive way, while others such as PostgreSQL are always case sensitive. It is therefore recommended to always assume case-sensitive comparisons, and to explicitly make comparisons case-insensitive when unsure about the case. For example, instead of

+
SELECT * FROM concept WHERE concep_class_id = 'Clinical Finding'
+

it is preferred to use

+
SELECT * FROM concept WHERE LOWER(concep_class_id) = 'clinical finding'
+
+
+

+Schemas and databases

+

In SQL Server, tables are located in a schema, and schemas reside in a database. For example, cdm_data.dbo.person refers to the person table in the dbo schema in the cdm_data database. In other dialects, even though a similar hierarchy often exists they are used very differently. In SQL Server, there is typically one schema per database (often called dbo), and users can easily use data in different databases. On other platforms, for example in PostgreSQL, it is not possible to use data across databases in a single session, but there are often many schemas in a database. In PostgreSQL one could say that the equivalent of SQL Server’s database is the schema.

+

We therefore recommend concatenating SQL Server’s database and schema into a single parameter, which we typically call @databaseSchema. For example, we could have the parameterized SQL

+
SELECT * FROM @databaseSchema.person
+

where on SQL Server we can include both database and schema names in the value: databaseSchema = "cdm_data.dbo". On other platforms, we can use the same code, but now only specify the schema as the parameter value: databaseSchema = "cdm_data".

+

The one situation where this will fail is the USE command, since USE cdm_data.dbo; will throw an error. It is therefore preferred not to use the USE command, but always specify the database / schema where a table is located. However, if one wanted to use it anyway, we recommend creating two variables, one called @database and the other called @databaseSchema. For example, for this parameterized SQL:

+
SELECT * FROM @databaseSchema.person;
+USE @database;
+SELECT * FROM person
+

we can set database = "cdm_data" and the other called databaseSchema = "cdm_data.dbo". On platforms other than SQL Server, the two variables will hold the same value and only on SQL Server will they be different. Within an R function, it is even possible to derive one variable from the other, so the user of your function would need to specify only one value:

+
foo <- function(databaseSchema, dbms) {
+    database <- strsplit(databaseSchema, "\\.")[[1]][1]
+    sql <- "SELECT * FROM @databaseSchema.person; USE @database; SELECT * FROM person;"
+    sql <- renderSql(sql, databaseSchema = databaseSchema, database = database)$sql
+    sql <- translateSql(sql, targetDialect = dbms)$sql
+    return(sql)
+}
+foo("cdm_data.dbo", "sql server")
+
#> [1] "SELECT * FROM cdm_data.dbo.person; USE cdm_data; SELECT * FROM person;"
+
foo("cdm_data", "postgresql")
+
#> [1] "SELECT * FROM cdm_data.person; SET search_path TO cdm_data; SELECT * FROM person;"
+
+
+

+Optimization for massively parallel processing

+

Both PDW and RedShift are massively parallel processing platforms, meaning they consist of many nodes that work together. In such an environment, significant increases in performance can be achieved by finetuning the SQL for these platforms. Probably most importantly, developers can specify the way data is distributed over the nodes. Ideally, data in a node only needs to be combined with data in the same node. For example, if I have two tables with the field person_id, I would like all records with the same person ID to be on the same node, so a join on person_id can be performed locally without exchanging data between nodes.

+

SQL Server SQL, our source dialect, does not allow for these optimizations, so we’ve introduced the notion of hints. In the following example, a hint is provided on which field should be used for the distribution of data across nodes:

+
--HINT DISTRIBUTE_ON_KEY(person_id)
+SELECT * INTO one_table FROM other_table;
+

which will translate into the following on PDW:

+
--HINT DISTRIBUTE_ON_KEY(person_id)
+IF XACT_STATE() = 1 COMMIT; 
+CREATE TABLE one_table WITH (DISTRIBUTION = HASH(person_id)) AS
+SELECT * FROM other_table;
+

Another tuning parameter is the key to sort a table on. This can be also be specified in a hint:

+
--HINT SORT_ON_KEY(INTERLEAVED:start_date)
+CREATE TABLE cdm.my_table (row_id INT, start_date);
+

translates to the following on RedShift:

+
--HINT SORT_ON_KEY(INTERLEAVED:start_date)
+CREATE TABLE cdm.my_table (row_id INT, start_date)
+INTERLEAVED SORTKEY(start_date);
+

The hints should be formatted exactly as shown above, and directly precede the statement where the table is created.

+
+
+
+

+Debugging parameterized SQL

+

Debugging parameterized SQL can be a bit complicated; Only the rendered SQL can be tested against a database server, but changes to the code should be made in the parameterized (pre-rendered) SQL.

+

A Shiny app is included in the SqlRender package for interactively editing source SQL and generating rendered and translated SQL. The app can be started using:

+ +

Which will open the default browser with the app.

+

In addition, two functions have been developed to aid the debugging process: renderSqlFile() and translateSqlFile(). These can be used to read SQL from file, render or translate it, and write it back to file. For example:

+
translateSqlFile("parameterizedSql.txt", "renderedSql.txt")
+

will render the file, using the default parameter values specified in the SQL. What works well for us is editing in the parameterized file, (re)running the command above, and have the rendered SQL file open in a SQL client for testing. Any problems reported by the server can be dealt with in the source SQL, and can quickly be re-rendered.

+
+
+

+Developing R packages that contain parameterized SQL

+

Often, the SQL code will become part of an R package, where it might be used to perform initial data-preprocessing and extraction before further analysis. We’ve developed the following practice for doing so: The parameterized SQL should be located in the inst/sql/ folder of the package. The parameterized SQL for SQL Server should be in the inst/sql/sql_server/ folder. If for some reason you do not want to use the translation functions to generate the SQL for some dialect (e.g because dialect specific code might be written that gives better performance), a dialect-specific version of the parameterized SQL should be placed in a folder with the name of that dialect, for example inst/sql/oracle/. SqlRender has a function loadRenderTranslateSql() that will first check if a dialect-specific version is available for the target dialect. If it is, that version will be rendered, else the SQL Server version will be rendered and subsequently translated to the target dialect.

+

The createRWrapperForSql() function can be used to create an R wrapper around a rendered SQL file, using the loadRenderTranslateSql() function . For example, suppose we have a text file called test.sql containing the following parameterized SQL:

+
{DEFAULT @selected_value = 1}
+SELECT * FROM table INTO result where x = @selected_value;
+

Then the command

+
createRWrapperForSql(sqlFilename = "test.sql", 
+                     rFilename = "test.R", 
+                     packageName = "myPackage")
+

would result in the file test.R being generated containing this R code:

+
#' Todo: add title
+#'
+#' @description
+#' Todo: add description
+#'
+#' @details
+#' Todo: add details
+#'
+#' @param connectionDetails   An R object of type \code{ConnectionDetails} created ...
+#' @param selectedValue
+#'
+#' @export
+test <- function(connectionDetails, selectedValue = 1) {
+    renderedSql <- loadRenderTranslateSql("test.txt", packageName = "myPackage", 
+        dbms = connectionDetails$dbms, selected_value = selectedValue)
+    conn <- connect(connectionDetails)
+    
+    writeLines("Executing multiple queries. This could take a while")
+    executeSql(conn, renderedSql)
+    writeLines("Done")
+    
+    dummy <- dbDisconnect(conn)
+}
+

This code expects the file test.sql to be located in the inst/sql/sql_server/ folder of the package source.

+

Note that the parameters are identified by the declaration of default values, and that snake_case names (our standard for SQL) are converted to camelCase names (our standard for R).

+
+
+
+ + + +
+ + +
+ +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/articles/index.html b/docs/articles/index.html new file mode 100644 index 00000000..768a200b --- /dev/null +++ b/docs/articles/index.html @@ -0,0 +1,106 @@ + + + + + + + + +Articles • SqlRender + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+

All vignettes

+

+ + +
+
+
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/authors.html b/docs/authors.html new file mode 100644 index 00000000..e0dd9a0c --- /dev/null +++ b/docs/authors.html @@ -0,0 +1,111 @@ + + + + + + + + +Authors • SqlRender + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + +
    +
  • +

    Martijn Schuemie. Author, maintainer. +

    +
  • +
  • +

    Marc Suchard. Author. +

    +
  • +
+ +
+ +
+ + +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 00000000..c378a521 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,241 @@ + + + + + + + +Rendering Parameterized SQL and Translation to Dialects • SqlRender + + + + + + +
+
+ + + +
+
+ +
+ + +
+
+

+Introduction

+

This is an R package for rendering parameterized SQL, and translating it to different SQL dialects. SqlRender can also be used as a stand-alone Java library and a command-line executable.

+
+
+

+Features

+
    +
  • Supports a simple markup syntax for making SQL parameterized, and renders parameterized SQL (containing the markup syntax) to executable SQL
  • +
  • The syntax supports defining default parameter values
  • +
  • The syntax supports if-then-else structures
  • +
  • Has functions for translating SQL from one dialect (Microsoft SQL Server) to other dialects (Oracle, PostgreSQL, Amazon RedShift, Impala, IBM Netezza, Google BigQuery, and Microsoft PDW)
  • +
  • Can be used as R package, Java library, or as stand-alone executable through a command-line interface
  • +
+
+
+

+Examples

+

This exampe shows the use of parameters, as well as SqlRender’s {if} ? {then} : {else} syntax:

+
sql <- renderSql("SELECT * FROM @a; {@b != ''}?{USE @b;}", a = "my_table", b = "my_schema")$sql
+

will produce the variable sql containing this value:

+
"SELECT * FROM my_table; USE my_schema;"
+

subsequently running this code

+
sql <- translateSql(sql, "sql server", "oracle")$sql
+

will produce the variable sql containing this value:

+
"SELECT * FROM my_table; ALTER SESSION SET current_schema =  my_schema;"
+
+
+

+Technology

+

The SqlRender package is an R package wrapped around a Java library. The rJava package is used as interface.

+

The Java library is available as a JAR file.

+
+
+

+System Requirements

+

Running the package requires R with the package rJava installed. Also requires Java 1.6 or higher.

+
+
+

+Dependencies

+
    +
  • There are no dependencies.
  • +
+
+
+

+Getting Started

+
+

+R package

+

In R, use the following commands to install the latest stable version from CRAN:

+
install.packages("SqlRender")
+

To install the latest development version directly from GitHub, use:

+
install.packages("devtools")
+library(devtools)
+install_github("ohdsi/SqlRender")
+

Once installed, you can try out SqlRender in a Shiny app that comes with the package:

+
library(SqlRender)
+launchSqlRenderDeveloper()
+
+
+

+Java library

+

You can fetch the JAR file in the inst/java folder of this repository, or use Maven:

+
    +
  1. +

    First add the SqlRender repository so that maven can find and download the SqlRender artifact automatically:

    +
    <repositories>
    +<repository>
    +    <id>ohdsi</id>
    +    <name>repo.ohdsi.org</name>
    +    <url>http://repo.ohdsi.org:8085/nexus/content/repositories/releases</url>
    +</repository>
    +<repository>
    +    <id>ohdsi.snapshots</id>
    +    <name>repo.ohdsi.org-snapshots</name>
    +    <url>http://repo.ohdsi.org:8085/nexus/content/repositories/snapshots</url>
    +    <releases>
    +        <enabled>false</enabled>
    +    </releases>
    +    <snapshots>
    +        <enabled>true</enabled>
    +    </snapshots>
    +</repository>
    +</repositories>
    +

    2: Include the SqlRender dependency in your pom.xml

    +
    <dependency>
    +<groupId>org.ohdsi.sql</groupId>
    +<artifactId>SqlRender</artifactId>
    +<version>1.0.0-SNAPSHOT</version>
    +</dependency>
    +
  2. +
+
+
+

+Command-line executable

+

You can fetch the JAR file in the inst/java folder of this repository, or use Maven as described above. Run this from the command line to get a list of options:

+
java -jar SqlRender.jar ?
+
+
+
+

+Getting Involved

+ +
+
+

+License

+

SqlRender is licensed under Apache License 2.0

+
+
+

+Development

+

SqlRender is being developed in R Studio.

+
+

+Development status

+

Build Status codecov.io

+

Stable. The code is actively being used in several projects.

+
+
+
+

+Acknowledgements

+
    +
  • This project is supported in part through the National Science Foundation grant IIS 1251151.
  • +
+
+ +
+ + +
+ + +
+ +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/jquery.sticky-kit.min.js b/docs/jquery.sticky-kit.min.js new file mode 100644 index 00000000..e2a3c6de --- /dev/null +++ b/docs/jquery.sticky-kit.min.js @@ -0,0 +1,9 @@ +/* + Sticky-kit v1.1.2 | WTFPL | Leaf Corcoran 2015 | http://leafo.net +*/ +(function(){var b,f;b=this.jQuery||window.jQuery;f=b(window);b.fn.stick_in_parent=function(d){var A,w,J,n,B,K,p,q,k,E,t;null==d&&(d={});t=d.sticky_class;B=d.inner_scrolling;E=d.recalc_every;k=d.parent;q=d.offset_top;p=d.spacer;w=d.bottoming;null==q&&(q=0);null==k&&(k=void 0);null==B&&(B=!0);null==t&&(t="is_stuck");A=b(document);null==w&&(w=!0);J=function(a,d,n,C,F,u,r,G){var v,H,m,D,I,c,g,x,y,z,h,l;if(!a.data("sticky_kit")){a.data("sticky_kit",!0);I=A.height();g=a.parent();null!=k&&(g=g.closest(k)); +if(!g.length)throw"failed to find stick parent";v=m=!1;(h=null!=p?p&&a.closest(p):b("
"))&&h.css("position",a.css("position"));x=function(){var c,f,e;if(!G&&(I=A.height(),c=parseInt(g.css("border-top-width"),10),f=parseInt(g.css("padding-top"),10),d=parseInt(g.css("padding-bottom"),10),n=g.offset().top+c+f,C=g.height(),m&&(v=m=!1,null==p&&(a.insertAfter(h),h.detach()),a.css({position:"",top:"",width:"",bottom:""}).removeClass(t),e=!0),F=a.offset().top-(parseInt(a.css("margin-top"),10)||0)-q, +u=a.outerHeight(!0),r=a.css("float"),h&&h.css({width:a.outerWidth(!0),height:u,display:a.css("display"),"vertical-align":a.css("vertical-align"),"float":r}),e))return l()};x();if(u!==C)return D=void 0,c=q,z=E,l=function(){var b,l,e,k;if(!G&&(e=!1,null!=z&&(--z,0>=z&&(z=E,x(),e=!0)),e||A.height()===I||x(),e=f.scrollTop(),null!=D&&(l=e-D),D=e,m?(w&&(k=e+u+c>C+n,v&&!k&&(v=!1,a.css({position:"fixed",bottom:"",top:c}).trigger("sticky_kit:unbottom"))),eb&&!v&&(c-=l,c=Math.max(b-u,c),c=Math.min(q,c),m&&a.css({top:c+"px"})))):e>F&&(m=!0,b={position:"fixed",top:c},b.width="border-box"===a.css("box-sizing")?a.outerWidth()+"px":a.width()+"px",a.css(b).addClass(t),null==p&&(a.after(h),"left"!==r&&"right"!==r||h.append(a)),a.trigger("sticky_kit:stick")),m&&w&&(null==k&&(k=e+u+c>C+n),!v&&k)))return v=!0,"static"===g.css("position")&&g.css({position:"relative"}), +a.css({position:"absolute",bottom:d,top:"auto"}).trigger("sticky_kit:bottom")},y=function(){x();return l()},H=function(){G=!0;f.off("touchmove",l);f.off("scroll",l);f.off("resize",y);b(document.body).off("sticky_kit:recalc",y);a.off("sticky_kit:detach",H);a.removeData("sticky_kit");a.css({position:"",bottom:"",top:"",width:""});g.position("position","");if(m)return null==p&&("left"!==r&&"right"!==r||a.insertAfter(h),h.remove()),a.removeClass(t)},f.on("touchmove",l),f.on("scroll",l),f.on("resize", +y),b(document.body).on("sticky_kit:recalc",y),a.on("sticky_kit:detach",H),setTimeout(l,0)}};n=0;for(K=this.length;n + + + + + diff --git a/docs/pkgdown.css b/docs/pkgdown.css new file mode 100644 index 00000000..bcc0bd74 --- /dev/null +++ b/docs/pkgdown.css @@ -0,0 +1,158 @@ +/* Sticker footer */ +body > .container { + display: flex; + padding-top: 60px; + min-height: calc(100vh); + flex-direction: column; +} + +body > .container .row { + flex: 1; +} + +footer { + margin-top: 45px; + padding: 35px 0 36px; + border-top: 1px solid #e5e5e5; + color: #666; + display: flex; +} +footer p { + margin-bottom: 0; +} +footer div { + flex: 1; +} +footer .pkgdown { + text-align: right; +} +footer p { + margin-bottom: 0; +} + +img.icon { + float: right; +} + +img { + max-width: 100%; +} + +/* Section anchors ---------------------------------*/ + +a.anchor { + margin-left: -30px; + display:inline-block; + width: 30px; + height: 30px; + visibility: hidden; + + background-image: url(./link.svg); + background-repeat: no-repeat; + background-size: 20px 20px; + background-position: center center; +} + +.hasAnchor:hover a.anchor { + visibility: visible; +} + +@media (max-width: 767px) { + .hasAnchor:hover a.anchor { + visibility: hidden; + } +} + + +/* Fixes for fixed navbar --------------------------*/ + +.contents h1, .contents h2, .contents h3, .contents h4 { + padding-top: 60px; + margin-top: -60px; +} + +/* Static header placement on mobile devices */ +@media (max-width: 767px) { + .navbar-fixed-top { + position: absolute; + } + .navbar { + padding: 0; + } +} + + +/* Sidebar --------------------------*/ + +#sidebar { + margin-top: 30px; +} +#sidebar h2 { + font-size: 1.5em; + margin-top: 1em; +} + +#sidebar h2:first-child { + margin-top: 0; +} + +#sidebar .list-unstyled li { + margin-bottom: 0.5em; +} + +/* Reference index & topics ----------------------------------------------- */ + +.ref-index th {font-weight: normal;} +.ref-index h2 {font-size: 20px;} + +.ref-index td {vertical-align: top;} +.ref-index .alias {width: 40%;} +.ref-index .title {width: 60%;} + +.ref-index .alias {width: 40%;} +.ref-index .title {width: 60%;} + +.ref-arguments th {text-align: right; padding-right: 10px;} +.ref-arguments th, .ref-arguments td {vertical-align: top;} +.ref-arguments .name {width: 20%;} +.ref-arguments .desc {width: 80%;} + +/* Nice scrolling for wide elements --------------------------------------- */ + +table { + display: block; + overflow: auto; +} + +/* Syntax highlighting ---------------------------------------------------- */ + +pre { + word-wrap: normal; + word-break: normal; + border: 1px solid #eee; +} + +pre, code { + background-color: #f8f8f8; + color: #333; +} + +pre img { + background-color: #fff; + display: block; +} + +code a, pre a { + color: #375f84; +} + +.fl {color: #1514b5;} +.fu {color: #000000;} /* function */ +.ch,.st {color: #036a07;} /* string */ +.kw {color: #264D66;} /* keyword */ +.co {color: #888888;} /* comment */ + +.message { color: black; font-weight: bolder;} +.error { color: orange; font-weight: bolder;} +.warning { color: #6A0366; font-weight: bolder;} + diff --git a/docs/pkgdown.js b/docs/pkgdown.js new file mode 100644 index 00000000..c8b38c49 --- /dev/null +++ b/docs/pkgdown.js @@ -0,0 +1,8 @@ +$(function() { + $("#sidebar").stick_in_parent({offset_top: 40}); + $('body').scrollspy({ + target: '#sidebar', + offset: 60 + }); + +}); diff --git a/docs/reference/SqlRender.html b/docs/reference/SqlRender.html new file mode 100644 index 00000000..6a79e9db --- /dev/null +++ b/docs/reference/SqlRender.html @@ -0,0 +1,110 @@ + + + + + + + + +SqlRender SqlRender • SqlRender + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

SqlRender

+ + + + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/camelCaseToSnakeCase.html b/docs/reference/camelCaseToSnakeCase.html new file mode 100644 index 00000000..72bff165 --- /dev/null +++ b/docs/reference/camelCaseToSnakeCase.html @@ -0,0 +1,131 @@ + + + + + + + + +Convert a camel case string to snake case camelCaseToSnakeCase • SqlRender + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Convert a camel case string to snake case

+ + +
camelCaseToSnakeCase(string)
+ +

Arguments

+ + + + + + +
string

The string to be converted

+ +

Value

+ +

A string

+ + +

Examples

+
camelCaseToSnakeCase("cdmDatabaseSchema")
#> [1] "cdm_database_schema"
# > 'cdm_database_schema'
+
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/createRWrapperForSql.html b/docs/reference/createRWrapperForSql.html new file mode 100644 index 00000000..7ede8d0f --- /dev/null +++ b/docs/reference/createRWrapperForSql.html @@ -0,0 +1,153 @@ + + + + + + + + +Create an R wrapper for SQL createRWrapperForSql • SqlRender + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

createRWrapperForSql creates an R wrapper for a parameterized SQL file. The created R script +file will contain a single function, that executes the SQL, and accepts the same parameters as +specified in the SQL.

+ + +
createRWrapperForSql(sqlFilename, rFilename, packageName,
+  createRoxygenTemplate = TRUE)
+ +

Arguments

+ + + + + + + + + + + + + + + + + + +
sqlFilename

The SQL file.

rFilename

The name of the R file to be generated. Defaults to the name of the +SQL file with the extention reset to R.

packageName

The name of the package that will contains the SQL file.

createRoxygenTemplate

If true, a template of Roxygen comments will be added.

+ +

Details

+ +

This function reads the declarations of defaults in the parameterized SQL file, and creates an R +function that exposes the parameters. It uses the loadRenderTranslateSql function, and +assumes the SQL will be used inside a package. To use inside a package, the SQL file should be +placed in the inst/sql/sql_server folder of the package.

+ + +

Examples

+
not_run({ + # This will create a file called CohortMethod.R: + createRWrapperForSql("CohortMethod.sql", packageName = "CohortMethod") +})
+
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/index.html b/docs/reference/index.html new file mode 100644 index 00000000..1f68ea1d --- /dev/null +++ b/docs/reference/index.html @@ -0,0 +1,205 @@ + + + + + + + + +Function reference • SqlRender + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

All functions

+

+
+

camelCaseToSnakeCase

+

Convert a camel case string to snake case

+

createRWrapperForSql

+

Create an R wrapper for SQL

+

launchSqlRenderDeveloper

+

Launch the SqlRender Developer Shiny app

+

loadRenderTranslateSql

+

Load, render, and translate a SQL file in a package

+

readSql

+

Reads a SQL file

+

renderSql

+

renderSql

+

renderSqlFile

+

Render a SQL file

+

snakeCaseToCamelCase

+

Convert a snake case string to camel case

+

splitSql

+

splitSql

+

SqlRender

+

SqlRender

+

translateSql

+

translateSql

+

translateSqlFile

+

Translate a SQL file

+

writeSql

+

Write SQL to a SQL (text) file

+
+
+ + +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/launchSqlRenderDeveloper.html b/docs/reference/launchSqlRenderDeveloper.html new file mode 100644 index 00000000..129592fd --- /dev/null +++ b/docs/reference/launchSqlRenderDeveloper.html @@ -0,0 +1,128 @@ + + + + + + + + +Launch the SqlRender Developer Shiny app launchSqlRenderDeveloper • SqlRender + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Launch the SqlRender Developer Shiny app

+ + +
launchSqlRenderDeveloper(launch.browser = TRUE)
+ +

Arguments

+ + + + + + +
launch.browser

Should the app be launched in your default browser, or in a Shiny window. +Note: copying to clipboard will not work in a Shiny window.

+ +

Details

+ +

Launches a Shiny app that allows the user to develop SQL and see how it translates to the supported dialects.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/loadRenderTranslateSql.html b/docs/reference/loadRenderTranslateSql.html new file mode 100644 index 00000000..e4616795 --- /dev/null +++ b/docs/reference/loadRenderTranslateSql.html @@ -0,0 +1,165 @@ + + + + + + + + +Load, render, and translate a SQL file in a package loadRenderTranslateSql • SqlRender + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

loadRenderTranslateSql Loads a SQL file contained in a package, renders it and translates it +to the specified dialect

+ + +
loadRenderTranslateSql(sqlFilename, packageName, dbms = "sql server", ...,
+  oracleTempSchema = NULL)
+ +

Arguments

+ + + + + + + + + + + + + + + + + + + + + + +
sqlFilename

The source SQL file

packageName

The name of the package that contains the SQL file

dbms

The target dialect. Currently 'sql server', 'oracle', 'postgres', and +'redshift' are supported

...

Parameter values used for renderSql

oracleTempSchema

A schema that can be used to create temp tables in when using Oracle.

+ +

Value

+ +

Returns a string containing the rendered SQL.

+ +

Details

+ +

This function looks for a SQL file with the specified name in the inst/sql/<dbms> folder of the +specified package. If it doesn't find it in that folder, it will try and load the file from the +inst/sql/sql_server folder and use the translateSql function to translate it to the +requested dialect. It will subsequently call the renderSql function with any of the +additional specified parameters.

+ + +

Examples

+
not_run({ + renderedSql <- loadRenderTranslateSql("CohortMethod.sql", + packageName = "CohortMethod", + dbms = connectionDetails$dbms, + CDM_schema = "cdmSchema") +})
+
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/readSql.html b/docs/reference/readSql.html new file mode 100644 index 00000000..feffb48f --- /dev/null +++ b/docs/reference/readSql.html @@ -0,0 +1,139 @@ + + + + + + + + +Reads a SQL file readSql • SqlRender + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

readSql loads SQL from a file

+ + +
readSql(sourceFile)
+ +

Arguments

+ + + + + + +
sourceFile

The source SQL file

+ +

Value

+ +

Returns a string containing the SQL.

+ +

Details

+ +

readSql loads SQL from a file

+ + +

Examples

+
not_run({ + readSql("myParamStatement.sql") +})
+
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/renderSql.html b/docs/reference/renderSql.html new file mode 100644 index 00000000..c74f876e --- /dev/null +++ b/docs/reference/renderSql.html @@ -0,0 +1,244 @@ + + + + + + + + +renderSql renderSql • SqlRender + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

renderSql Renders SQL code based on parameterized SQL and parameter values.

+ + +
renderSql(sql = "", ...)
+ +

Arguments

+ + + + + + + + + + +
sql

The parameterized SQL

...

Parameter values

+ +

Value

+ +

A list containing the following elements:

+
parameterizedSql

The original +parameterized SQL code

sql

The rendered sql

+ + +

Details

+ +

This function takes parameterized SQL and a list of parameter values and renders the SQL that can +be send to the server. Parameterization syntax:

+
@parameterName

Parameters are +indicated using a @ prefix, and are replaced with the actual values provided in the renderSql +call.

{DEFAULT @parameterName = parameterValue}

Default values for parameters can be +defined using curly and the DEFAULT keyword.

{if}?{then}:{else}

The if-then-else +pattern is used to turn on or off blocks of SQL code.

+ + +

Examples

+
renderSql("SELECT * FROM @a;", a = "myTable")
#> $originalSql +#> [1] "SELECT * FROM @a;" +#> +#> $sql +#> [1] "SELECT * FROM myTable;" +#> +#> $parameters +#> $parameters$a +#> [1] "myTable" +#> +#>
renderSql("SELECT * FROM @a {@b}?{WHERE x = 1};", a = "myTable", b = "true")
#> $originalSql +#> [1] "SELECT * FROM @a {@b}?{WHERE x = 1};" +#> +#> $sql +#> [1] "SELECT * FROM myTable WHERE x = 1;" +#> +#> $parameters +#> $parameters$a +#> [1] "myTable" +#> +#> $parameters$b +#> [1] "true" +#> +#>
renderSql("SELECT * FROM @a {@b == ''}?{WHERE x = 1}:{ORDER BY x};", a = "myTable", b = "true")
#> $originalSql +#> [1] "SELECT * FROM @a {@b == ''}?{WHERE x = 1}:{ORDER BY x};" +#> +#> $sql +#> [1] "SELECT * FROM myTable ORDER BY x;" +#> +#> $parameters +#> $parameters$a +#> [1] "myTable" +#> +#> $parameters$b +#> [1] "true" +#> +#>
renderSql("SELECT * FROM @a {@b != ''}?{WHERE @b = 1};", a = "myTable", b = "y")
#> $originalSql +#> [1] "SELECT * FROM @a {@b != ''}?{WHERE @b = 1};" +#> +#> $sql +#> [1] "SELECT * FROM myTable WHERE y = 1;" +#> +#> $parameters +#> $parameters$a +#> [1] "myTable" +#> +#> $parameters$b +#> [1] "y" +#> +#>
renderSql("SELECT * FROM @a {1 IN (@c)}?{WHERE @b = 1};", + a = "myTable", + b = "y", + c = c(1, 2, 3, 4))
#> $originalSql +#> [1] "SELECT * FROM @a {1 IN (@c)}?{WHERE @b = 1};" +#> +#> $sql +#> [1] "SELECT * FROM myTable WHERE y = 1;" +#> +#> $parameters +#> $parameters$a +#> [1] "myTable" +#> +#> $parameters$b +#> [1] "y" +#> +#> $parameters$c +#> [1] "1,2,3,4" +#> +#>
renderSql("{DEFAULT @b = \"someField\"}SELECT * FROM @a {@b != ''}?{WHERE @b = 1};", + a = "myTable")
#> $originalSql +#> [1] "{DEFAULT @b = \"someField\"}SELECT * FROM @a {@b != ''}?{WHERE @b = 1};" +#> +#> $sql +#> [1] "SELECT * FROM myTable WHERE someField = 1;" +#> +#> $parameters +#> $parameters$a +#> [1] "myTable" +#> +#>
renderSql("SELECT * FROM @a {@a == 'myTable' & @b != 'x'}?{WHERE @b = 1};", + a = "myTable", + b = "y")
#> $originalSql +#> [1] "SELECT * FROM @a {@a == 'myTable' & @b != 'x'}?{WHERE @b = 1};" +#> +#> $sql +#> [1] "SELECT * FROM myTable WHERE y = 1;" +#> +#> $parameters +#> $parameters$a +#> [1] "myTable" +#> +#> $parameters$b +#> [1] "y" +#> +#>
+
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/renderSqlFile.html b/docs/reference/renderSqlFile.html new file mode 100644 index 00000000..facdd4e5 --- /dev/null +++ b/docs/reference/renderSqlFile.html @@ -0,0 +1,148 @@ + + + + + + + + +Render a SQL file renderSqlFile • SqlRender + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

renderSqlFile Renders SQL code in a file based on parameterized SQL and parameter values, +and writes it to another file.

+ + +
renderSqlFile(sourceFile, targetFile, ...)
+ +

Arguments

+ + + + + + + + + + + + + + +
sourceFile

The source SQL file

targetFile

The target SQL file

...

Parameter values

+ +

Details

+ +

This function takes parameterized SQL and a list of parameter values and renders the SQL that can +be send to the server. Parameterization syntax:

+
@parameterName

Parameters are +indicated using a @ prefix, and are replaced with the actual values provided in the renderSql +call.

{DEFAULT @parameterName = parameterValue}

Default values for parameters can be +defined using curly and the DEFAULT keyword.

{if}?{then}:{else}

The if-then-else +pattern is used to turn on or off blocks of SQL code.

+ + +

Examples

+
not_run({ + renderSqlFile("myParamStatement.sql", "myRenderedStatement.sql", a = "myTable") +})
+
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/snakeCaseToCamelCase.html b/docs/reference/snakeCaseToCamelCase.html new file mode 100644 index 00000000..ab794ad1 --- /dev/null +++ b/docs/reference/snakeCaseToCamelCase.html @@ -0,0 +1,131 @@ + + + + + + + + +Convert a snake case string to camel case snakeCaseToCamelCase • SqlRender + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Convert a snake case string to camel case

+ + +
snakeCaseToCamelCase(string)
+ +

Arguments

+ + + + + + +
string

The string to be converted

+ +

Value

+ +

A string

+ + +

Examples

+
snakeCaseToCamelCase("cdm_database_schema")
#> [1] "cdmDatabaseSchema"
# > 'cdmDatabaseSchema'
+
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/splitSql.html b/docs/reference/splitSql.html new file mode 100644 index 00000000..734442a4 --- /dev/null +++ b/docs/reference/splitSql.html @@ -0,0 +1,139 @@ + + + + + + + + +splitSql splitSql • SqlRender + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

splitSql splits a string containing multiple SQL statements into a vector of SQL statements

+ + +
splitSql(sql)
+ +

Arguments

+ + + + + + +
sql

The SQL string to split into separate statements

+ +

Value

+ +

A vector of strings, one for each SQL statement

+ +

Details

+ +

This function is needed because some DBMSs (like ORACLE) do not accepts multiple SQL statements +being sent as one execution.

+ + +

Examples

+
splitSql("SELECT * INTO a FROM b; USE x; DROP TABLE c;")
#> [1] "SELECT * INTO a FROM b" "USE x" "DROP TABLE c"
+
+
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/translateSql.html b/docs/reference/translateSql.html new file mode 100644 index 00000000..61e4f346 --- /dev/null +++ b/docs/reference/translateSql.html @@ -0,0 +1,162 @@ + + + + + + + + +translateSql translateSql • SqlRender + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

translateSql translates SQL from one dialect to another

+ + +
translateSql(sql = "", targetDialect, oracleTempSchema = NULL,
+  sourceDialect)
+ +

Arguments

+ + + + + + + + + + + + + + + + + + +
sql

The SQL to be translated

targetDialect

The target dialect. Currently "oracle", "postgresql", "pdw", "impala", "netezza", "bigquery", and +"redshift" are supported

oracleTempSchema

A schema that can be used to create temp tables in when using Oracle or Impala.

sourceDialect

Deprecated: The source dialect. Currently, only "sql server" for Microsoft SQL Server +is supported

+ +

Value

+ +

A list containing the following elements:

+
originalSql

The original parameterized +SQL code

sql

The translated SQL

+ + +

Details

+ +

This function takes SQL in one dialect and translates it into another. It uses simple pattern +replacement, so its functionality is limited.

+ + +

Examples

+
translateSql("USE my_schema;", targetDialect = "oracle")
#> $originalSql +#> [1] "USE my_schema;" +#> +#> $sql +#> [1] "ALTER SESSION SET current_schema = my_schema;" +#>
+
+
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/translateSqlFile.html b/docs/reference/translateSqlFile.html new file mode 100644 index 00000000..d2f92f69 --- /dev/null +++ b/docs/reference/translateSqlFile.html @@ -0,0 +1,154 @@ + + + + + + + + +Translate a SQL file translateSqlFile • SqlRender + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

This function takes SQL and translates it to a different dialect.

+ + +
translateSqlFile(sourceFile, targetFile, sourceDialect, targetDialect,
+  oracleTempSchema = NULL)
+ +

Arguments

+ + + + + + + + + + + + + + + + + + + + + + +
sourceFile

The source SQL file

targetFile

The target SQL file

sourceDialect

Deprecated: The source dialect. Currently, only 'sql server' for Microsoft SQL Server +is supported

targetDialect

The target dialect. Currently 'oracle', 'postgresql', and 'redshift' are +supported

oracleTempSchema

A schema that can be used to create temp tables in when using Oracle.

+ +

Details

+ +

This function takes SQL and translates it to a different dialect.

+ + +

Examples

+
not_run({ + translateSqlFile("myRenderedStatement.sql", + "myTranslatedStatement.sql", + targetDialect = "postgresql") +})
+
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/writeSql.html b/docs/reference/writeSql.html new file mode 100644 index 00000000..c2270ebc --- /dev/null +++ b/docs/reference/writeSql.html @@ -0,0 +1,138 @@ + + + + + + + + +Write SQL to a SQL (text) file writeSql • SqlRender + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

writeSql writes SQL to a file

+ + +
writeSql(sql, targetFile)
+ +

Arguments

+ + + + + + + + + + +
sql

A string containing the sql

targetFile

The target SQL file

+ +

Details

+ +

writeSql writes SQL to a file

+ + +

Examples

+
not_run({ + sql <- "SELECT * FROM @table_name" + writeSql(sql, "myParamStatement.sql") +})
+
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/extras/PackageMaintenance.R b/extras/PackageMaintenance.R index bb07bb3e..892879ca 100644 --- a/extras/PackageMaintenance.R +++ b/extras/PackageMaintenance.R @@ -1,6 +1,6 @@ # @file PackageMaintenance # -# Copyright 2016 Observational Health Data Sciences and Informatics +# Copyright 2017 Observational Health Data Sciences and Informatics # # This file is part of SqlRender # @@ -29,4 +29,11 @@ rmarkdown::render("vignettes/UsingSqlRender.Rmd", output_file = "../inst/doc/UsingSqlRender.pdf", rmarkdown::pdf_document(latex_engine = "pdflatex", toc = TRUE, - number_sections = TRUE)) \ No newline at end of file + number_sections = TRUE)) + +pkgdown::build_site() + +# Release package: +devtools::build_win() + +devtools::release() diff --git a/extras/SqlRender.pdf b/extras/SqlRender.pdf index 897badcd..6140501f 100644 Binary files a/extras/SqlRender.pdf and b/extras/SqlRender.pdf differ diff --git a/inst/csv/replacementPatterns.csv b/inst/csv/replacementPatterns.csv index 1b0ab6ec..5f20e2c8 100644 --- a/inst/csv/replacementPatterns.csv +++ b/inst/csv/replacementPatterns.csv @@ -1,385 +1,489 @@ -From,To,Pattern,Replacement -"sql server","oracle","INSERT INTO @table (@columns) VALUES (@values1),(@values2)"," INSERT INTO @table (@columns) VALUES (INTO @table @columns VALUES @values1\n INTO @table @columns VALUES @values2\n)" -"sql server","oracle","INTO @table @columns VALUES INTO @table @columns VALUES","INTO @table @columns VALUES" -"sql server","oracle"," @a INSERT INTO @table (@columns) VALUES (@b)","INSERT ALL\n@bSELECT * FROM dual" -"sql server","oracle","","(" -"sql server","oracle","",")" -"sql server","oracle","EXCEPT","MINUS" -"sql server","oracle","DATEADD(d,@days,@date)","(@date + @days)" -"sql server","oracle","DATEADD(dd,@days,@date)","(@date + @days)" -"sql server","oracle","DATEADD(day,@days,@date)","(@date + @days)" -"sql server","oracle","DATEADD(month,@months,@date)","ADD_MONTHS(@date, @months)" -"sql server","oracle","DATEADD(mm,@months,@date)","ADD_MONTHS(@date, @months)" -"sql server","oracle","DATEADD(m,@months,@date)","ADD_MONTHS(@date, @months)" -"sql server","oracle","DATEADD(year,@years,@date)","ADD_MONTHS(@date, 12 * @years)" -"sql server","oracle","DATEADD(yyyy,@years,@date)","ADD_MONTHS(@date, 12 * @years)" -"sql server","oracle","DATEADD(yy,@years,@date)","ADD_MONTHS(@date, 12 * @years)" -"sql server","oracle","DATEDIFF(day,@start, @end)","(@end - @start)" -"sql server","oracle","DATEDIFF(dd,@start, @end)","(@end - @start)" -"sql server","oracle","DATEDIFF(d,@start, @end)","(@end - @start)" -"sql server","oracle","GETDATE()","SYSDATE" -"sql server","oracle","+ '@a'","|| '@a'" -"sql server","oracle","'@a' +","'@a' ||" -"sql server","oracle","CAST(@a AS varchar(@b)) +","CAST(@a AS varchar(@b)) ||" -"sql server","oracle","+ CAST(@a AS varchar(@b))","|| CAST(@a AS varchar(@b))" -"sql server","oracle","CAST(@a AS varchar) +","CAST(@a AS varchar) ||" -"sql server","oracle","+ CAST(@a AS varchar)","|| CAST(@a AS varchar)" -"sql server","oracle","CAST(@a AS DATE)","TO_DATE(@a, 'yyyymmdd')" -"sql server","oracle","CAST(@a AS VARCHAR(@b))","TO_CHAR(@a)" -"sql server","oracle","CAST(@a AS VARCHAR)","TO_CHAR(@a)" -"sql server","oracle","DATEFROMPARTS(@year,@month,@day)","TO_DATE(TO_CHAR(@year,'0000')||'-'||TO_CHAR(@month,'00')||'-'||TO_CHAR(@day,'00'), 'YYYY-MM-DD')" -"sql server","oracle","DATETIMEFROMPARTS(@year,@month,@day,@hour,@minute,@second,@ms)","TO_DATE(TO_CHAR(@year,'0000')||'-'||TO_CHAR(@month,'00')||'-'||TO_CHAR(@day,'00')||' '||TO_CHAR(@hour,'00')||':'||TO_CHAR(@minute,'00')||':'||TO_CHAR(@second,'00'), 'YYYY-MM-DD HH24:MI:SS')" -"sql server","oracle","YEAR(@date)","EXTRACT(YEAR FROM @date)" -"sql server","oracle","MONTH(@date)","EXTRACT(MONTH FROM @date)" -"sql server","oracle","DAY(@date)","EXTRACT(DAY FROM @date)" -"sql server","oracle","EOMONTH(@date)","LAST_DAY(@date)" -"sql server","oracle","STDEV(@a)","STDDEV(@a)" -"sql server","oracle","VAR(@a)","VARIANCE(@a)" -"sql server","oracle","RAND()","DBMS_RANDOM.VALUE" -"sql server","oracle","CEILING(@a)","CEIL(@a)" -"sql server","oracle","HASHBYTES('MD5',@a)","DBMS_CRYPTO.HASH(@a,2)" -"sql server","oracle","LEN(@a)","LENGTH(@a)" -"sql server","oracle","LEFT(@str,@chars)","SUBSTR(@str,0,@chars)" -"sql server","oracle","RIGHT(@str,@chars)","SUBSTR(@str,-@chars)" -"sql server","oracle","LOG(@expression)","LOG(2.718281828459, @expression)" -"sql server","oracle","LOG10(@expression)","LOG(10,@expression)" -"sql server","oracle","ISNULL(@a,@b)","NVL(@a,@b)" -"sql server","oracle","COUNT_BIG(@a)","COUNT(@a)" -"sql server","oracle","SQUARE(@a)","((@a)*(@a))" -"sql server","oracle","PI()","3.14159265358979" -"sql server","oracle","NEWID()","SYS_GUID()" -"sql server","oracle","CHARINDEX(@a,@b)","INSTR(@b,@a)" -"sql server","oracle","SELECT @a WHERE @b;","SELECT @a FROM DUAL WHERE @b;" -"sql server","oracle","(SELECT @a WHERE @b)","(SELECT @a FROM DUAL WHERE @b)" -"sql server","oracle","SELECT @a;","SELECT @a FROM DUAL;" -"sql server","oracle","(SELECT @a)","(SELECT @a FROM DUAL)" -"sql server","oracle","SELECT @a FROM @b FROM DUAL","SELECT @a FROM @b" -"sql server","oracle","SELECT @a FROM @b FROM DUAL","SELECT @a FROM @b" -"sql server","oracle","IF OBJECT_ID('@table', 'U') IS NULL CREATE TABLE @table (@definition);","BEGIN\n EXECUTE IMMEDIATE 'CREATE TABLE @table (@definition)';\nEXCEPTION\n WHEN OTHERS THEN\n IF SQLCODE != -955 THEN\n RAISE;\n END IF;\nEND;" -"sql server","oracle","IF OBJECT_ID('tempdb..#@table', 'U') IS NOT NULL DROP TABLE #@table;","BEGIN\n EXECUTE IMMEDIATE 'TRUNCATE TABLE %temp_prefix%%session_id%@table';\n EXECUTE IMMEDIATE 'DROP TABLE %temp_prefix%%session_id%@table';\nEXCEPTION\n WHEN OTHERS THEN\n IF SQLCODE != -942 THEN\n RAISE;\n END IF;\nEND;" -"sql server","oracle","IF OBJECT_ID('@table', 'U') IS NOT NULL DROP TABLE @table;","BEGIN\n EXECUTE IMMEDIATE 'TRUNCATE TABLE @table';\n EXECUTE IMMEDIATE 'DROP TABLE @table';\nEXCEPTION\n WHEN OTHERS THEN\n IF SQLCODE != -942 THEN\n RAISE;\n END IF;\nEND;" -"sql server","oracle","USE @schema;","ALTER SESSION SET current_schema = @schema;" -"sql server","oracle",".dbo.","." -"sql server","oracle","CREATE CLUSTERED INDEX","CREATE INDEX" -"sql server","oracle","CREATE UNIQUE INDEX @name ON @table (@variable);","BEGIN\n EXECUTE IMMEDIATE 'CREATE UNIQUE INDEX @name ON @table (@variable)';\nEXCEPTION\n WHEN OTHERS THEN\n IF SQLCODE != -1408 THEN\n RAISE;\n END IF;\nEND;" -"sql server","oracle","CREATE UNIQUE CLUSTERED INDEX @name ON @table (@variable);","BEGIN\n EXECUTE IMMEDIATE 'CREATE UNIQUE INDEX @name ON @table (@variable)';\nEXCEPTION\n WHEN OTHERS THEN\n IF SQLCODE != -1408 THEN\n RAISE;\n END IF;\nEND;" -"sql server","oracle","PRIMARY KEY NONCLUSTERED","PRIMARY KEY" -"sql server","oracle","DATETIME","TIMESTAMP" -"sql server","oracle","BIGINT","NUMBER(19)" -"sql server","oracle","VARCHAR(MAX)","CLOB" -"sql server","oracle","WITH @a AS @b SELECT @c INTO @d FROM @e;","CREATE TABLE @d\nAS\nWITH @a AS @b SELECT\n@c\nFROM\n@e;" -"sql server","oracle","WITH @a AS @b INSERT INTO @c SELECT @d;","INSERT INTO @c WITH @a AS @b SELECT @d;" -"sql server","oracle","SELECT @a INTO @b FROM @c;","CREATE TABLE @b AS\nSELECT\n@a\nFROM\n@c;" -"sql server","oracle","SELECT @a INTO @b;","CREATE TABLE @b AS\nSELECT\n@a;" -"sql server","oracle","#","%temp_prefix%%session_id%" -"sql server","postgresql","ROUND(@a,@b)","ROUND(CAST(@a AS NUMERIC),@b)" -"sql server","postgresql","CAST(@a AS DATE)","TO_DATE(@a, 'yyyymmdd')" -"sql server","postgresql","DATEADD(d,@days,@date)","(@date + @days)" -"sql server","postgresql","DATEADD(dd,@days,@date)","(@date + @days)" -"sql server","postgresql","DATEADD(day,@days,@date)","(@date + @days)" -"sql server","postgresql","DATEADD(m,@months,@date)","CAST((@date + @months*INTERVAL'1 month') AS DATE)" -"sql server","postgresql","DATEADD(mm,@months,@date)","CAST((@date + @months*INTERVAL'1 month') AS DATE)" -"sql server","postgresql","DATEADD(month,@months,@date)","CAST((@date + @months*INTERVAL'1 month') AS DATE)" -"sql server","postgresql","DATEADD(yy,@years,@date)","CAST((@date + @years*INTERVAL'1 year') AS DATE)" -"sql server","postgresql","DATEADD(yyyy,@years,@date)","CAST((@date + @years*INTERVAL'1 year') AS DATE)" -"sql server","postgresql","DATEADD(year,@years,@date)","CAST((@date + @years*INTERVAL'1 year') AS DATE)" -"sql server","postgresql","DATEDIFF(d,@start, @end)","(CAST(@end AS DATE) - CAST(@start AS DATE))" -"sql server","postgresql","DATEDIFF(dd,@start, @end)","(CAST(@end AS DATE) - CAST(@start AS DATE))" -"sql server","postgresql","DATEDIFF(day,@start, @end)","(CAST(@end AS DATE) - CAST(@start AS DATE))" -"sql server","postgresql","GETDATE()","CURRENT_DATE" -"sql server","postgresql","+ '@a'","|| '@a'" -"sql server","postgresql","'@a' +","'@a' ||" -"sql server","postgresql","CAST(@a AS varchar(@b)) +","CAST(@a AS varchar(@b)) ||" -"sql server","postgresql","+ CAST(@a AS varchar(@b))","|| CAST(@a AS varchar(@b))" -"sql server","postgresql","CAST(@a AS varchar) +","CAST(@a AS varchar) ||" -"sql server","postgresql","+ CAST(@a AS varchar)","|| CAST(@a AS varchar)" -"sql server","postgresql","DATEFROMPARTS(@year,@month,@day)","TO_DATE(TO_CHAR(@year,'0000')||'-'||TO_CHAR(@month,'00')||'-'||TO_CHAR(@day,'00'), 'YYYY-MM-DD')" -"sql server","postgresql","DATETIMEFROMPARTS(@year,@month,@day,@hour,@minute,@second,@ms)","TO_DATE(TO_CHAR(@year,'0000')||'-'||TO_CHAR(@month,'00')||'-'||TO_CHAR(@day,'00')||' '||TO_CHAR(@hour,'00')||':'||TO_CHAR(@minute,'00')||':'||TO_CHAR(@second,'00'), 'YYYY-MM-DD HH24:MI:SS')" -"sql server","postgresql","YEAR(@date)","EXTRACT(YEAR FROM @date)" -"sql server","postgresql","MONTH(@date)","EXTRACT(MONTH FROM @date)" -"sql server","postgresql","DAY(@date)","EXTRACT(DAY FROM @date)" -"sql server","postgresql","EOMONTH(@date)","(DATE_TRUNC('MONTH', @date) + INTERVAL '1 MONTH - 1 day')::DATE" -"sql server","postgresql","STDEV(@a)","STDDEV(@a)" -"sql server","postgresql","VAR(@a)","VARIANCE(@a)" -"sql server","postgresql","RAND()","RANDOM()" -"sql server","postgresql","HASHBYTES('MD5',@a)","MD5(@a)" -"sql server","postgresql","LEN(@a)","CHAR_LENGTH(@a)" -"sql server","postgresql","CHARINDEX(@a,@b)","STRPOS(@b,@a)" -"sql server","postgresql","LOG(@expression)","LN(@expression)" -"sql server","postgresql","LOG10(@expression)","LOG(10,@expression)" -"sql server","postgresql","ISNULL(@a,@b)","COALESCE(@a,@b)" -"sql server","postgresql","COUNT_BIG(@a)","COUNT(@a)" -"sql server","postgresql","SQUARE(@a)","((@a)*(@a))" -"sql server","postgresql","NEWID()","MD5(RANDOM()::TEXT || CLOCK_TIMESTAMP()::TEXT)" -"sql server","postgresql","USE @schema;","SET search_path TO @schema;" -"sql server","postgresql","IF OBJECT_ID('@table', 'U') IS NULL CREATE TABLE @table (@definition);","CREATE TABLE IF NOT EXISTS @table (@definition);" -"sql server","postgresql","IF OBJECT_ID('@table', 'U') IS NOT NULL DROP TABLE @table;","DROP TABLE IF EXISTS @table;" -"sql server","postgresql","IF OBJECT_ID('tempdb..#@table', 'U') IS NOT NULL DROP TABLE @table;","DROP TABLE IF EXISTS @table;" -"sql server","postgresql",".dbo.","." -"sql server","postgresql","CREATE TABLE #@table (@definition)","CREATE TEMP TABLE @table (@definition)" -"sql server","postgresql","CREATE CLUSTERED INDEX @index_name ON @table (@variable);","CREATE INDEX @index_name ON @table (@variable);\nCLUSTER @table USING @index_name;" -"sql server","postgresql","CREATE UNIQUE CLUSTERED INDEX @index_name ON @table (@variable);","CREATE UNIQUE INDEX @index_name ON @table (@variable);\nCLUSTER @table USING @index_name;" -"sql server","postgresql","PRIMARY KEY NONCLUSTERED","PRIMARY KEY" -"sql server","postgresql","DATETIME","TIMESTAMP" -"sql server","postgresql","VARCHAR(MAX)","TEXT" -"sql server","postgresql","FLOAT","NUMERIC" -"sql server","postgresql","WITH @a AS @b SELECT @c INTO #@d FROM @e;","CREATE TEMP TABLE @d\nAS\nWITH @a AS @b SELECT\n@c\nFROM\n@e;" -"sql server","postgresql","WITH @a AS @b SELECT @c INTO @d FROM @e;","CREATE TABLE @d\nAS\nWITH @a AS @b SELECT\n@c\nFROM\n@e;" -"sql server","postgresql","SELECT @a INTO #@b FROM @c;","CREATE TEMP TABLE @b\nAS\nSELECT\n@a\nFROM\n@c;" -"sql server","postgresql","SELECT @a INTO @b FROM @c;","CREATE TABLE @b AS\nSELECT\n@a\nFROM\n@c;" -"sql server","postgresql","SELECT @a INTO @b;","CREATE TABLE @b AS\nSELECT\n@a;" -"sql server","postgresql","#","" -"sql server","redshift","ROUND(@a,@b)","ROUND(CAST(@a AS FLOAT),@b)" -"sql server","redshift","CAST(@a AS DATE)","TO_DATE(@a, 'yyyymmdd')" -"sql server","redshift","DATEADD(d,@days,@date)","(@date + @days)" -"sql server","redshift","DATEADD(dd,@days,@date)","(@date + @days)" -"sql server","redshift","DATEADD(day,@days,@date)","(@date + @days)" -"sql server","redshift","DATEADD(m,@months,@date)","CAST(ADD_MONTHS(@date,@months) AS DATE)" -"sql server","redshift","DATEADD(mm,@months,@date)","CAST(ADD_MONTHS(@date,@months) AS DATE)" -"sql server","redshift","DATEADD(month,@months,@date)","CAST(ADD_MONTHS(@date,@months) AS DATE)" -"sql server","redshift","DATEDIFF(d,@start, @end)","(@end - @start)" -"sql server","redshift","DATEDIFF(dd,@start, @end)","(@end - @start)" -"sql server","redshift","DATEDIFF(day,@start, @end)","(@end - @start)" -"sql server","redshift","GETDATE()","CURRENT_DATE" -"sql server","redshift","+ '@a'","|| '@a'" -"sql server","redshift","'@a' +","'@a' ||" -"sql server","redshift","CAST(@a AS varchar(@b)) +","CAST(@a AS varchar(@b)) ||" -"sql server","redshift","+ CAST(@a AS varchar(@b))","|| CAST(@a AS varchar(@b))" -"sql server","redshift","CAST(@a AS varchar) +","CAST(@a AS varchar) ||" -"sql server","redshift","+ CAST(@a AS varchar)","|| CAST(@a AS varchar)" -"sql server","redshift","DATEFROMPARTS(@year,@month,@day)","TO_DATE(TO_CHAR(@year,'0000')||'-'||TO_CHAR(@month,'00')||'-'||TO_CHAR(@day,'00'), 'YYYY-MM-DD')" -"sql server","redshift","YEAR(@date)","EXTRACT(YEAR FROM @date)" -"sql server","redshift","MONTH(@date)","EXTRACT(MONTH FROM @date)" -"sql server","redshift","DAY(@date)","EXTRACT(DAY FROM @date)" -"sql server","redshift","STDEV(@a)","STDDEV(@a)" -"sql server","redshift","RAND()","RANDOM()" -"sql server","redshift","HASHBYTES('MD5',@a)","MD5(@a)" -"sql server","redshift","LEN(@a)","CHAR_LENGTH(@a)" -"sql server","redshift","LOG(@expression)","LN(CAST(@expression AS REAL))" -"sql server","redshift","ISNULL(@a,@b)","COALESCE(@a,@b)" -"sql server","redshift","COUNT_BIG(@a)","COUNT(@a)" -"sql server","redshift","USE @schema;","SET search_path TO @schema;" -"sql server","redshift","IF OBJECT_ID('@table', 'U') IS NULL CREATE TABLE @table (@definition);","CREATE TABLE IF NOT EXISTS @table (@definition);" -"sql server","redshift","IF OBJECT_ID('@table', 'U') IS NOT NULL DROP TABLE @table;","DROP TABLE IF EXISTS @table;" -"sql server","redshift","IF OBJECT_ID('tempdb..#@table', 'U') IS NOT NULL DROP TABLE @table;","DROP TABLE IF EXISTS @table;" -"sql server","redshift",".dbo.","." -"sql server","redshift","CREATE TABLE #@table (@definition)","CREATE TEMP TABLE @table (@definition)" -"sql server","redshift","WITH @a AS @b SELECT @c INTO #@d FROM @e;","CREATE TEMP TABLE @d\nAS\nWITH @a AS @b SELECT\n@c\nFROM\n@e;" -"sql server","redshift","WITH @a AS @b SELECT @c INTO @d FROM @e;","CREATE TABLE @d\nAS\nWITH @a AS @b SELECT\n@c\nFROM\n@e;" -"sql server","redshift","SELECT @a INTO #@b FROM @c;","CREATE TEMP TABLE @b\nAS\nSELECT\n@a\nFROM\n@c;" -"sql server","redshift","SELECT @a INTO @b FROM @c;","CREATE TABLE @b AS\nSELECT\n@a\nFROM\n@c;" -"sql server","redshift","SELECT @a INTO @b;","CREATE TABLE @b AS\nSELECT\n@a;" -"sql server","redshift","PRIMARY KEY NONCLUSTERED","PRIMARY KEY" -"sql server","redshift","DATETIME","TIMESTAMP" -"sql server","redshift","#","" -"sql server","pdw","VARCHAR(MAX)","VARCHAR(1000)" -"sql server","pdw","WITH @a AS @b SELECT @c1 subject_id, @c2 INTO @d FROM @e;","CREATE TABLE @d WITH (DISTRIBUTION = HASH(subject_id))\nAS\nWITH @a AS @b SELECT\n@c1 subject_id, @c2\nFROM\n@e;" -"sql server","pdw","WITH @a AS @b SELECT @c1 person_id, @c2 INTO @d FROM @e;","CREATE TABLE @d WITH (DISTRIBUTION = HASH(person_id))\nAS\nWITH @a AS @b SELECT\n@c1 person_id, @c2\nFROM\n@e;" -"sql server","pdw","WITH @a AS @b SELECT @c1 analysis_id, @c2 INTO @d FROM @e;","CREATE TABLE @d WITH (DISTRIBUTION = HASH(analysis_id))\nAS\nWITH @a AS @b SELECT\n@c1 analysis_id, @c2\nFROM\n@e;" -"sql server","pdw","WITH @a AS @b SELECT @c INTO @d FROM @e;","CREATE TABLE @d WITH (DISTRIBUTION = REPLICATE)\nAS\nWITH @a AS @b SELECT\n@c\nFROM\n@e;" -"sql server","pdw","SELECT @a1 subject_id, @a2 INTO @b FROM @c;","CREATE TABLE @b WITH (DISTRIBUTION = HASH(subject_id))\nAS\nSELECT\n@a1 subject_id, @a2\nFROM\n@c;" -"sql server","pdw","SELECT @a1 person_id, @a2 INTO @b FROM @c;","CREATE TABLE @b WITH (DISTRIBUTION = HASH(person_id))\nAS\nSELECT\n@a1 person_id, @a2\nFROM\n@c;" -"sql server","pdw","SELECT @a1 analysis_id, @a2 INTO @b FROM @c;","CREATE TABLE @b WITH (DISTRIBUTION = HASH(analysis_id))\nAS\nSELECT\n@a1 analysis_id, @a2\nFROM\n@c;" -"sql server","pdw","SELECT @a INTO @b FROM @c;","CREATE TABLE @b WITH (DISTRIBUTION = REPLICATE)\nAS\nSELECT\n@a\nFROM\n@c;" -"sql server","pdw","SELECT @a INTO @b;","CREATE TABLE @b WITH (DISTRIBUTION = REPLICATE)\nAS\nSELECT\n@a;" -"sql server","pdw","CREATE TABLE #@a WITH (DISTRIBUTION = @b) AS","CREATE TABLE #@a WITH (LOCATION = USER_DB, DISTRIBUTION = @b) AS" -"sql server","pdw","CREATE TABLE @table (@definition_part1 subject_id @definition_part2);","CREATE TABLE @table (@definition_part1 subject_id @definition_part2)\nWITH (DISTRIBUTION = HASH(subject_id));" -"sql server","pdw","CREATE TABLE @table (@definition_part1 person_id @definition_part2);","CREATE TABLE @table (@definition_part1 person_id @definition_part2)\nWITH (DISTRIBUTION = HASH(person_id));" -"sql server","pdw","CREATE TABLE @table (@definition_part1 analysis_id @definition_part2);","CREATE TABLE @table (@definition_part1 analysis_id @definition_part2)\nWITH (DISTRIBUTION = HASH(analysis_id));" -"sql server","pdw","CREATE TABLE @table (@definition);","CREATE TABLE @table (@definition)\nWITH (DISTRIBUTION = REPLICATE);" -"sql server","pdw","CREATE TABLE #@table (@definition) WITH (DISTRIBUTION = @distribution);","CREATE TABLE #@table (@definition)\nWITH (LOCATION = USER_DB, DISTRIBUTION = @distribution);" -"sql server","pdw","TRUNCATE TABLE ","IF XACT_STATE() = 1 COMMIT; TR*NC*T* TABLE " -"sql server","pdw","DROP TABLE ","IF XACT_STATE() = 1 COMMIT; DR*P TABLE " -"sql server","pdw","CREATE TABLE ","IF XACT_STATE() = 1 COMMIT; CR**T* TABLE " -"sql server","pdw","TR*NC*T*","TRUNCATE" -"sql server","pdw","DR*P","DROP" -"sql server","pdw","CR**T*","CREATE" -"sql server","pdw","IF OBJECT_ID(@a) IS NOT NULL IF XACT_STATE() = 1 COMMIT;","IF XACT_STATE() = 1 COMMIT; IF OBJECT_ID(@a) IS NOT NULL " -"sql server","mysql","DATEADD(d,@days,@date)","DATE_ADD(@date,INTERVAL @days DAY)" -"sql server","mysql","DATEADD(dd,@days,@date)","DATE_ADD(@date,INTERVAL @days DAY)" -"sql server","mysql","DATEADD(day,@days,@date)","DATE_ADD(@date,INTERVAL @days DAY)" -"sql server","mysql","DATEADD(m,@months,@date)","DATE_ADD(@date,INTERVAL @months MONTH)" -"sql server","mysql","DATEADD(mm,@months,@date)","DATE_ADD(@date,INTERVAL @months MONTH)" -"sql server","mysql","DATEADD(month,@months,@date)","DATE_ADD(@date,INTERVAL @months MONTH)" -"sql server","mysql","DATEADD(yy,@years,@date)","DATE_ADD(@date,INTERVAL @years YEAR)" -"sql server","mysql","DATEADD(yyyy,@years,@date)","DATE_ADD(@date,INTERVAL @years YEAR)" -"sql server","mysql","DATEADD(year,@years,@date)","DATE_ADD(@date,INTERVAL @years YEAR)" -"sql server","mysql","DATEDIFF(d,@start, @end)","DATEDIFF(@start,@end)" -"sql server","mysql","DATEDIFF(dd,@start, @end)","DATEDIFF(@start,@end)" -"sql server","mysql","DATEDIFF(day,@start, @end)","DATEDIFF(@start,@end)" -"sql server","mysql","CAST(@a AS VARCHAR(@b))","CAST(@a AS CHAR(@b))" -"sql server","mysql","CAST(@a+@b+@c AS DATE)","CAST(concat(@a,'-',@b,'-',@c) AS DATE)" -"sql server","mysql","RIGHT(@str1+@str2,@chars)","RIGHT(CONCAT(@str1,@str2),@chars)" -"sql server","mysql","GETDATE()","NOW()" -"sql server","mysql","DATEFROMPARTS(@year,@month,@day)"," DATE_ADD(DATE_ADD(MAKEDATE(@year, 1), INTERVAL (@month)-1 MONTH), INTERVAL (@day)-1 DAY)" -"sql server","mysql","EOMONTH(@date)","LAST_DAY(@date)" -"sql server","mysql","STDEV(@a)","STDDEV(@a)" -"sql server","mysql","VAR(@a)","VARIANCE(@a)" -"sql server","mysql","HASHBYTES('MD5',@a)","MD5(@a)" -"sql server","mysql","LEN(@a)","LENGTH(@a)" -"sql server","mysql","COUNT_BIG(@a)","COUNT(@a)" -"sql server","mysql","LOG(@expression)","LN(@expression)" -"sql server","mysql","LOG10(@expression)","LOG(10,@expression)" -"sql server","mysql","SQUARE(@a)","((@a)*(@a))" -"sql server","mysql","IF OBJECT_ID('@table', 'U') IS NULL CREATE TABLE @table (@definition);","CREATE TABLE IF NOT EXISTS @table (@definition);" -"sql server","mysql","IF OBJECT_ID('@table', 'U') IS NOT NULL DROP TABLE @table;","DROP TABLE IF EXISTS @table;" -"sql server","mysql","IF OBJECT_ID('tempdb..#@table', 'U') IS NOT NULL DROP TABLE @table;","DROP TABLE IF EXISTS @table;" -"sql server","mysql","CREATE CLUSTERED INDEX @index_name ON @table (@variable);","CREATE INDEX @index_name ON @table (@variable);" -"sql server","mysql","CREATE UNIQUE CLUSTERED INDEX @index_name ON @table (@variable);","CREATE UNIQUE INDEX @index_name ON @table (@variable);" -"sql server","mysql","PRIMARY KEY NONCLUSTERED","PRIMARY KEY" -"sql server","mysql","VARCHAR(MAX)","TEXT" -"sql server","mysql","FLOAT","NUMERIC" -"sql server","mysql","WITH @tablea (@definitiona) AS @ba, @tableb (@definitionb) as @bb, @tablec (@definitionc) as @bc, @tabled (@definitiond) as @bd SELECT @c INTO #@d FROM @e;","CREATE TABLE IF NOT EXISTS @tablea @ba;CREATE TABLE IF NOT EXISTS @tableb @bb;CREATE TABLE IF NOT EXISTS @tablec @bc; CREATE TABLE IF NOT EXISTS @tabled @bd; CREATE TABLE IF NOT EXISTS @d SELECT @c FROM @e;Drop table @tablea,@tableb,@tablec,@tabled;" -"sql server","mysql","WITH @tablea (@definitiona) AS @ba, @tableb (@definitionb) as @bb, @tablec (@definitionc) as @bc SELECT @c INTO #@d FROM @e;","CREATE TABLE IF NOT EXISTS @tablea @ba;CREATE TABLE IF NOT EXISTS @tableb @bb;CREATE TABLE IF NOT EXISTS @tablec @bc; CREATE TABLE IF NOT EXISTS @d SELECT @c FROM @e;Drop table @tablea,@tableb,@tablec;" -"sql server","mysql","WITH @aa AS @ba, @ab as @bb, @ac as @bc,@ad as @bd SELECT @c INTO #@d FROM @e;","CREATE TABLE IF NOT EXISTS @aa AS @ba;CREATE TABLE IF NOT EXISTS @ab @bb;CREATE TABLE IF NOT EXISTS @ac @bc;CREATE TABLE IF NOT EXISTS @ad @bd; CREATE TABLE IF NOT EXISTS @d SELECT @c FROM @e;Drop table @aa,@ab,@ac,@ad;" -"sql server","mysql","WITH @table (@definition) AS @b SELECT @c INTO #@d FROM @e;","CREATE TABLE IF NOT EXISTS @table @b; CREATE TABLE IF NOT EXISTS @d SELECT @c FROM @e;Drop table @table;" -"sql server","mysql","WITH @a AS @b SELECT @c INTO #@d FROM @e;","CREATE TABLE IF NOT EXISTS @a @b; CREATE TABLE IF NOT EXISTS @d SELECT @c FROM @e;Drop table @a;" -"sql server","mysql","WITH @a AS @b SELECT @c INTO @d FROM @e;","CREATE TABLE IF NOT EXISTS @a @b; CREATE TABLE IF NOT EXISTS @d SELECT @c FROM @e;Drop table @a;" -"sql server","mysql","SELECT @a INTO #@b FROM @c;","CREATE TEMPORARY TABLE @b SELECT @a FROM @c;" -"sql server","mysql","SELECT @a INTO @b FROM @c;","CREATE TABLE @b SELECT @a FROM @c;" -"sql server","mysql","SELECT @a INTO @b;","CREATE TABLE @b SELECT @a;" -"sql server","mysql","(SELECT @a,@b,@c,@d, ROW_NUMBER() over (PARTITION by @e order by @f) as @g FROM @h group by @i)","(select @a,@b,@c,@d, 0 as @g from @h group by @i)" -"sql server","mysql","SELECT @a,@b,@c,@d, ROW_NUMBER() over (PARTITION by @e order by @f) as @g FROM @h group by @i;","select @a,@b,@c,@d, 0 as @g from @h group by @i;" -"sql server","mysql","(SELECT @a,@b,@c,ROW_NUMBER() over (PARTITION by @d order by @e asc) as @f FROM @g)","(select @a,@b,@c, 0 as @f from @g)" -"sql server","mysql","(SELECT @a,@b, ROW_NUMBER() over (PARTITION by @d order by @e asc) as @f FROM @g)","(select @a,@b, 0 as @f from @g)" -"sql server","mysql","(SELECT @aa, ROW_NUMBER() over (PARTITION by @b order by @o asc) as @c FROM @d)","(select @aa, 0 as @c from @d)" -"sql server","mysql","(SELECT @aa, @ab, row_number() over (order by @b) as @c FROM @d group by @e)","(select @aa, @ab, 0 as @c from @d group by @e)" -"sql server","mysql","(SELECT @aa, @ab, @ac, row_number() over (order by @b) as @c FROM @d group by @e)","(select @aa, @ab,@ac, 0 as @c from @d group by @e)" -"sql server","mysql","IF OBJECT_ID('@table', 'U') IS NULL CREATE TABLE @table (@definition);","CREATE TABLE IF NOT EXISTS @table (@definition);" -"sql server","mysql","IF OBJECT_ID('@table', 'U') IS NOT NULL DROP TABLE @table;","DROP TABLE IF EXISTS @table;" -"sql server","mysql","IF OBJECT_ID('tempdb..#@table', 'U') IS NOT NULL DROP TABLE @table;","DROP TABLE IF EXISTS @table;" -"sql server","mysql",".dbo.","." -"sql server","mysql","(row_number() over (order by @a))","0" -"sql server","mysql","COUNT(@a) over ()","count(@a)" -"sql server","mysql","OBSERVATION_PERIOD","observation_period" -"sql server","mysql","temp_Dates","temp_dates" -"sql server","mysql","PERSON","person" -"sql server","mysql","#","" -"sql server","googlebigquery","DATEDIFF(d,@start, @end)","DATE_DIFF(DATE(@end), DATE(@start), DAY)" -"sql server","googlebigquery","DATEDIFF(dd,@start, @end)","DATE_DIFF(DATE(@end), DATE(@start), DAY)" -"sql server","googlebigquery","DATEDIFF(day,@start, @end)","DATE_DIFF(DATE(@end), DATE(@start), DAY)" -"sql server","googlebigquery","DATEADD(d,@days,@date)","DATE_ADD(DATE(@date), @days, DAY)" -"sql server","googlebigquery","DATEADD(dd,@days,@date)","DATE_ADD(DATE(@date), @days, DAY)" -"sql server","googlebigquery","DATEADD(day,@days,@date)","DATE_ADD(DATE(@date), @days, DAY)" -"sql server","googlebigquery","DATEADD(m,@months,@date)","DATE_ADD(DATE(@date), @months, MONTH)" -"sql server","googlebigquery","DATEADD(mm,@months,@date)","DATE_ADD(DATE(@date), @months, MONTH)" -"sql server","googlebigquery","DATEADD(month,@months,@date)","DATE_ADD(DATE(@date), @months, MONTH)" -"sql server","googlebigquery","GETDATE()","CURRENT_DATE()" -"sql server","googlebigquery","YEAR(@date)","EXTRACT(YEAR from @date)" -"sql server","googlebigquery","MONTH(@date)","EXTRACT(MONTH from @date)" -"sql server","googlebigquery","DAY(@date)","EXTRACT(DAY from @date)" -"sql server","googlebigquery","DATETIME","TIMESTAMP" -"sql server","googlebigquery","STDEV(@a)","STDDEV(@a)" -"sql server","googlebigquery","VAR(@a)","VARIANCE(@a)" -"sql server","googlebigquery","HASHBYTES('MD5',@a)","SHA1(@a)" -"sql server","googlebigquery","LEN(@a)","LENGTH(@a)" -"sql server","googlebigquery","COUNT_BIG(@a)","COUNT(@a)" -"sql server","googlebigquery","float",":float_temp" -"sql server","googlebigquery",":float_temp",":float" -"sql server","googlebigquery","varchar(@a)",":string" -"sql server","googlebigquery","varchar",":string" -"sql server","googlebigquery","bigint",":integer" -"sql server","googlebigquery","int",":integer" -"sql server","googlebigquery","CAST(@a as:string)","CAST(@a as string)" -"sql server","googlebigquery","CAST(@a as:integer)","CAST(@a as int64)" -"sql server","googlebigquery","CAST(@a as:float)","CAST(@a as float64)" -"sql server","googlebigquery","('@a')","'@a'" -"sql server","googlebigquery","'@a' + '@b'","CONCAT('@a','@b')" -"sql server","googlebigquery","CONCAT(@a) + CONCAT(@b)","CONCAT(@a,@b)" -"sql server","googlebigquery","CONCAT(@a) + '@b'","CONCAT(@a,'@b')" -"sql server","googlebigquery","'@a' + CONCAT(@b)","CONCAT('@a',@b)" -"sql server","googlebigquery","'@a'+@b,@c+","CONCAT('@a',@b),@c+" -"sql server","googlebigquery","'@a'+@b+@c,","CONCAT('@a',@b)+@c," -"sql server","googlebigquery","'@a' + @b +","CONCAT('@a',@b)+" -"sql server","googlebigquery","'@a'+@b as @c,","CONCAT('@a',@b) as @c," -"sql server","googlebigquery","'@a'+@b,@c as","CONCAT('@a',@b),@c as" -"sql server","googlebigquery","'@a' + @b as","CONCAT('@a',@b) as" -"sql server","googlebigquery","'@a' + @b,","CONCAT('@a',@b)," -"sql server","googlebigquery","'@a'+@b) from","CONCAT('@a',@b)) from" -"sql server","googlebigquery","(CONCAT(@a))","CONCAT(@a)" -"sql server","googlebigquery","'@a' + @b from","CONCAT('@a',@b) from" -"sql server","googlebigquery","'@a'+@b) as","CONCAT('@a',@b)) as" -"sql server","googlebigquery","(CONCAT(@a))","CONCAT(@a)" -"sql server","googlebigquery","'@a'+@b)@d,","CONCAT('@a',@b))@d," -"sql server","googlebigquery","'@a' + @b)","CONCAT('@a',@b))" -"sql server","googlebigquery","(CONCAT(@a))","CONCAT(@a)" -"sql server","googlebigquery","'@a' + @b;","CONCAT('@a',@b);" -"sql server","googlebigquery","CONCAT(@a)+@b,@c+","CONCAT(@a,@b),@c+" -"sql server","googlebigquery","CONCAT(@a) + @b +","CONCAT(@a,@b)+" -"sql server","googlebigquery","CONCAT(@a)+@b as @c,","CONCAT(@a,@b)as @c," -"sql server","googlebigquery","CONCAT(@a)+@b,@c as","CONCAT(@a,@b),@c as" -"sql server","googlebigquery","CONCAT(@a) + @b as","CONCAT(@a,@b) as" -"sql server","googlebigquery","CONCAT(@a) + @b,","CONCAT(@a,@b)," -"sql server","googlebigquery","CONCAT(@a)+@b) from","CONCAT(@a,@b)) from" -"sql server","googlebigquery","(CONCAT(@a))","CONCAT(@a)" -"sql server","googlebigquery","CONCAT(@a) + @b from","CONCAT(@a,@b) from" -"sql server","googlebigquery","CONCAT(@a)+@b) as","CONCAT(@a,@b)) as" -"sql server","googlebigquery","(CONCAT(@a))","CONCAT(@a)" -"sql server","googlebigquery","CONCAT(@a)+@b)@d,","CONCAT(@a,@b))@d," -"sql server","googlebigquery","(CONCAT(@a))","CONCAT(@a)" -"sql server","googlebigquery","CONCAT(@a) + @b)","CONCAT(@a,@b))" -"sql server","googlebigquery","(CONCAT(@a))","CONCAT(@a)" -"sql server","googlebigquery","CONCAT(@a) + @b;","CONCAT(@a,@b);" -"sql server","googlebigquery","+@a,@b+'@c'","+@a,CONCAT(@b,'@c')" -"sql server","googlebigquery",",(@a+@b+'@c'",",(@a+CONCAT(@b,'@c')" -"sql server","googlebigquery",",(@a+'@b'",",(CONCAT(@a,'@b')" -"sql server","googlebigquery","(CONCAT(@a))","CONCAT(@a)" -"sql server","googlebigquery","(@a,@b+'@c'","(@a,CONCAT(@b,'@c')" -"sql server","googlebigquery",",@a+@b+'@c'",",@a+CONCAT(@b,'@c')" -"sql server","googlebigquery","+(@a+'@b'","+(CONCAT(@a,'@b')" -"sql server","googlebigquery","(CONCAT(@a))","CONCAT(@a)" -"sql server","googlebigquery","(@a+@b+'@c'","(@a+CONCAT(@b,'@c')" -"sql server","googlebigquery","+select @a+'@b'","+select CONCAT(@a,'@b')" -"sql server","googlebigquery","select @a+@b+'@c'","select @a+CONCAT(@b,'@c')" -"sql server","googlebigquery","+@a+'@b'","+CONCAT(@a,'@b')" -"sql server","googlebigquery","select (@a+'@b'","select (CONCAT(@a,'@b')" -"sql server","googlebigquery","(CONCAT(@a))","CONCAT(@a)" -"sql server","googlebigquery","(select @a+'@b'","(select CONCAT(@a,'@b')" -"sql server","googlebigquery","(@a+'@b'","(CONCAT(@a,'@b')" -"sql server","googlebigquery","(CONCAT(@a))","CONCAT(@a)" -"sql server","googlebigquery",",@a,@b+'@c'",",@a,CONCAT(@b,'@c')" -"sql server","googlebigquery",",select @a+'@b'",",select CONCAT(@a,'@b')" -"sql server","googlebigquery","select @a,@b+'@c'","select @a,CONCAT(@b,'@c')" -"sql server","googlebigquery",",@a+'@b'",",CONCAT(@a,'@b')" -"sql server","googlebigquery","select @a+'@b'","select CONCAT(@a,'@b')" -"sql server","googlebigquery","+@a,@b+CONCAT(@c)","+@a,CONCAT(@b,@c)" -"sql server","googlebigquery",",(@a+@b+CONCAT(@c)",",(@a+CONCAT(@b,@c)" -"sql server","googlebigquery",",(@a+CONCAT(@b)",",(CONCAT(@a,@b)" -"sql server","googlebigquery","(CONCAT(@a))","CONCAT(@a)" -"sql server","googlebigquery","(@a,@b+CONCAT(@c)","(@a,CONCAT(@b,@c)" -"sql server","googlebigquery",",@a+@b+CONCAT(@c)",",@a+CONCAT(@b,@c)" -"sql server","googlebigquery","+(@a+CONCAT(@b)","+(CONCAT(@a,@b)" -"sql server","googlebigquery","(CONCAT(@a))","CONCAT(@a)" -"sql server","googlebigquery","(@a+@b+CONCAT(@c)","(@a+CONCAT(@b,@c)" -"sql server","googlebigquery","+select @a+CONCAT(@b)","+select CONCAT(@a,@b)" -"sql server","googlebigquery","select @a+@b+CONCAT(@c)","select @a+CONCAT(@b,@c)" -"sql server","googlebigquery","+@a+CONCAT(@b)","+CONCAT(@a,@b)" -"sql server","googlebigquery","select (@a+CONCAT(@b)","select (CONCAT(@a,@b)" -"sql server","googlebigquery","(CONCAT(@a))","CONCAT(@a)" -"sql server","googlebigquery","(select @a+CONCAT(@c)","(select CONCAT(@a,@b)" -"sql server","googlebigquery","(@a+CONCAT(@b)","(CONCAT(@a,@b)" -"sql server","googlebigquery","(CONCAT(@a))","CONCAT(@a)" -"sql server","googlebigquery",",@a,@b+CONCAT(@c)",",@a,CONCAT(@b,@c)" -"sql server","googlebigquery",",select @a+CONCAT(@b)",",select CONCAT(@a,@b)" -"sql server","googlebigquery","select @a,@b+CONCAT(@c)","select @a,CONCAT(@b,@c)" -"sql server","googlebigquery",",@a+CONCAT(@b)",",CONCAT(@a,@b)" -"sql server","googlebigquery","select @a+CONCAT(@b)","select CONCAT(@a,@b)" -"sql server","googlebigquery","#","" -"sql server","googlebigquery","select @a;","#standardSQL\n select @a;" -"sql server","googlebigquery","insert @a;","#standardSQL\n insert @a;" -"sql server","googlebigquery","update @a;","#standardSQL\n update @a;" -"sql server","googlebigquery","create @a;","#standardSQL\n create @a;" -"sql server","googlebigquery","drop @a;","#standardSQL\n drop @a;" -"sql server","googlebigquery","delete @a;","#standardSQL\n delete @a;" -"sql server","googlebigquery","with @a;","#standardSQL\n with @a;" - - - - - - - - - - - +To,Pattern,Replacement +oracle,"INSERT INTO @table (@columns) VALUES (@values1),(@values2)", INSERT INTO @table (@columns) VALUES (INTO @table @columns VALUES @values1\n INTO @table @columns VALUES @values2\n) +oracle,INTO @table @columns VALUES INTO @table @columns VALUES,INTO @table @columns VALUES +oracle, @a INSERT INTO @table (@columns) VALUES (@b),INSERT ALL\n@bSELECT * FROM dual +oracle,,( +oracle,,) +oracle,EXCEPT,MINUS +oracle,"CONCAT(@a, @b, @c)","CONCAT(@a, CONCAT(@b, @c))" +oracle,"DATEADD(second,@seconds,@datetime)","(@date + NUMTODSINTERVAL(@seconds, 'second'))" +oracle,"DATEADD(minute,@minutes,@datetime)","(@date + NUMTODSINTERVAL(@minutes, 'minute'))" +oracle,"DATEADD(hour,@hours,@datetime)","(@date + NUMTODSINTERVAL(@hours, 'hour'))" +oracle,"DATEADD(d,@days,@date)","(@date + NUMTODSINTERVAL(@days, 'day'))" +oracle,"DATEADD(dd,@days,@date)","(@date + NUMTODSINTERVAL(@days, 'day'))" +oracle,"DATEADD(day,@days,@date)","(@date + NUMTODSINTERVAL(@days, 'day'))" +oracle,"DATEADD(month,@months,@date)","ADD_MONTHS(@date, @months)" +oracle,"DATEADD(mm,@months,@date)","ADD_MONTHS(@date, @months)" +oracle,"DATEADD(m,@months,@date)","ADD_MONTHS(@date, @months)" +oracle,"DATEADD(year,@years,@date)","ADD_MONTHS(@date, 12 * @years)" +oracle,"DATEADD(yyyy,@years,@date)","ADD_MONTHS(@date, 12 * @years)" +oracle,"DATEADD(yy,@years,@date)","ADD_MONTHS(@date, 12 * @years)" +oracle,"DATEDIFF(day,@start, @end)",(CAST(@end AS DATE) - CAST(@start AS DATE)) +oracle,"DATEDIFF(dd,@start, @end)",(CAST(@end AS DATE) - CAST(@start AS DATE)) +oracle,"DATEDIFF(d,@start, @end)",(CAST(@end AS DATE) - CAST(@start AS DATE)) +oracle,"CONVERT(VARCHAR,@date,112)","TO_CHAR(@date, 'YYYYMMDD')" +oracle,GETDATE(),SYSDATE +oracle,+ '@a',|| '@a' +oracle,'@a' +,'@a' || +oracle,CAST(@a AS varchar(@b)) +,CAST(@a AS varchar(@b)) || +oracle,+ CAST(@a AS varchar(@b)),|| CAST(@a AS varchar(@b)) +oracle,CAST(@a AS varchar) +,CAST(@a AS varchar) || +oracle,+ CAST(@a AS varchar),|| CAST(@a AS varchar) +oracle,"CONVERT(DATE, @a)","TO_DATE(@a, 'yyyymmdd')" +oracle,CAST(@a AS VARCHAR(@b)),TO_CHAR(@a) +oracle,CAST(@a AS VARCHAR),TO_CHAR(@a) +oracle,"DATEFROMPARTS(@year,@month,@day)","TO_DATE(TO_CHAR(@year,'0000')||'-'||TO_CHAR(@month,'00')||'-'||TO_CHAR(@day,'00'), 'YYYY-MM-DD')" +oracle,"DATETIMEFROMPARTS(@year,@month,@day,@hour,@minute,@second,@ms)","TO_DATE(TO_CHAR(@year,'0000')||'-'||TO_CHAR(@month,'00')||'-'||TO_CHAR(@day,'00')||' '||TO_CHAR(@hour,'00')||':'||TO_CHAR(@minute,'00')||':'||TO_CHAR(@second,'00'), 'YYYY-MM-DD HH24:MI:SS')" +oracle,EOMONTH(@date),LAST_DAY(@date) +oracle,STDEV(@a),STDDEV(@a) +oracle,VAR(@a),VARIANCE(@a) +oracle,RAND(),DBMS_RANDOM.VALUE +oracle,CEILING(@a),CEIL(@a) +oracle,"HASHBYTES('MD5',@a)","DBMS_CRYPTO.HASH(@a,2)" +oracle,LEN(@a),LENGTH(@a) +oracle,"LEFT(@str,@chars)","SUBSTR(@str,0,@chars)" +oracle,"RIGHT(@str,@chars)","SUBSTR(@str,-@chars)" +oracle,"LOG(@expression,@base)","(@base,@expression)" +oracle,LOG(@expression),"LOG(2.718281828459,@expression)" +oracle,,LOG +oracle,LOG10(@expression),"LOG(10,@expression)" +oracle,"ISNULL(@a,@b)","NVL(@a,@b)" +oracle,ISNUMERIC(@a),"(LENGTH(TRIM(TRANSLATE(@a, ' +-.0123456789',' '))) IS NULL)" +oracle,COUNT_BIG(@a),COUNT(@a) +oracle,SQUARE(@a),((@a)*(@a)) +oracle,PI(),3.141592654 +oracle,NEWID(),SYS_GUID() +oracle,"CHARINDEX(@a,@b)","INSTR(@b,@a)" +oracle,SELECT @a WHERE @b;,SELECT @a FROM DUAL WHERE @b; +oracle,(SELECT @a WHERE @b),(SELECT @a FROM DUAL WHERE @b) +oracle,SELECT @a WHERE @b UNION,SELECT @a FROM DUAL WHERE @b UNION +oracle,SELECT @a;,SELECT @a FROM DUAL; +oracle,(SELECT @a),(SELECT @a FROM DUAL) +oracle,SELECT @a UNION,SELECT @a FROM DUAL UNION +oracle,SELECT @a FROM @b FROM DUAL;,SELECT @a FROM @b; +oracle,FROM @a FROM DUAL,FROM @a +oracle,FROM @a FROM DUAL,FROM @a +oracle,FROM @a FROM DUAL,FROM @a +oracle,FROM @a FROM DUAL,FROM @a +oracle,YEAR(@date),EXTRACT(YEAR FROM @date) +oracle,MONTH(@date),EXTRACT(MONTH FROM @date) +oracle,DAY(@date),EXTRACT(DAY FROM @date) +oracle,"IF OBJECT_ID('@table', 'U') IS NULL CREATE TABLE @table (@definition);",BEGIN\n EXECUTE IMMEDIATE 'CREATE TABLE @table (@definition)';\nEXCEPTION\n WHEN OTHERS THEN\n IF SQLCODE != -955 THEN\n RAISE;\n END IF;\nEND; +oracle,"IF OBJECT_ID('tempdb..#@table', 'U') IS NOT NULL DROP TABLE #@table;",BEGIN\n EXECUTE IMMEDIATE 'TRUNCATE TABLE %temp_prefix%%session_id%@table';\n EXECUTE IMMEDIATE 'DROP TABLE %temp_prefix%%session_id%@table';\nEXCEPTION\n WHEN OTHERS THEN\n IF SQLCODE != -942 THEN\n RAISE;\n END IF;\nEND; +oracle,"IF OBJECT_ID('@table', 'U') IS NOT NULL DROP TABLE @table;",BEGIN\n EXECUTE IMMEDIATE 'TRUNCATE TABLE @table';\n EXECUTE IMMEDIATE 'DROP TABLE @table';\nEXCEPTION\n WHEN OTHERS THEN\n IF SQLCODE != -942 THEN\n RAISE;\n END IF;\nEND; +oracle,USE @schema;,ALTER SESSION SET current_schema = @schema; +oracle,.dbo.,. +oracle,CREATE CLUSTERED INDEX,CREATE INDEX +oracle,CREATE UNIQUE INDEX @name ON @table (@variable);,BEGIN\n EXECUTE IMMEDIATE 'CREATE UNIQUE INDEX @name ON @table (@variable)';\nEXCEPTION\n WHEN OTHERS THEN\n IF SQLCODE != -1408 THEN\n RAISE;\n END IF;\nEND; +oracle,CREATE UNIQUE CLUSTERED INDEX @name ON @table (@variable);,BEGIN\n EXECUTE IMMEDIATE 'CREATE UNIQUE INDEX @name ON @table (@variable)';\nEXCEPTION\n WHEN OTHERS THEN\n IF SQLCODE != -1408 THEN\n RAISE;\n END IF;\nEND; +oracle,PRIMARY KEY NONCLUSTERED,PRIMARY KEY +oracle,DATETIME,TIMESTAMP +oracle,BIGINT,NUMBER(19) +oracle,VARCHAR(MAX),CLOB +oracle,WITH @a AS @b SELECT @c INTO @d FROM @e;,CREATE TABLE @d\nAS\nWITH @a AS @b SELECT\n@c\nFROM\n@e; +oracle,WITH @a AS @b INSERT INTO @c SELECT @d;,INSERT INTO @c WITH @a AS @b SELECT @d; +oracle,SELECT @a INTO @b FROM @c;,CREATE TABLE @b AS\nSELECT\n@a\nFROM\n@c; +oracle,SELECT @a INTO @b;,CREATE TABLE @b AS\nSELECT\n@a; +oracle,##, +oracle,#,%temp_prefix%%session_id% +oracle,,## +oracle,SELECT TOP @([0-9]+)rows @a;,SELECT @a WHERE ROWNUM <= @rows; +oracle,SELECT @a WHERE @b WHERE ROWNUM <= @rows;,SELECT @a WHERE @b AND ROWNUM <= @rows; +postgresql,"ROUND(@a,@b)","ROUND(CAST(@a AS NUMERIC),@b)" +postgresql,"CONVERT(DATE, @a)","TO_DATE(@a, 'yyyymmdd')" +postgresql,"DATEADD(second,@seconds,@datetime)",(@datetime + @seconds*INTERVAL'1 second') +postgresql,"DATEADD(minute,@minutes,@datetime)",(@datetime + @minutes*INTERVAL'1 minute') +postgresql,"DATEADD(hour,@hours,@datetime)",(@datetime + @hours*INTERVAL'1 hour') +postgresql,"DATEADD(d,@days,@date)",(@date + @days*INTERVAL'1 day') +postgresql,"DATEADD(dd,@days,@date)",(@date + @days*INTERVAL'1 day') +postgresql,"DATEADD(day,@days,@date)",(@date + @days*INTERVAL'1 day') +postgresql,"DATEADD(m,@months,@date)",(@date + @months*INTERVAL'1 month') +postgresql,"DATEADD(mm,@months,@date)",(@date + @months*INTERVAL'1 month') +postgresql,"DATEADD(month,@months,@date)",(@date + @months*INTERVAL'1 month') +postgresql,"DATEADD(yy,@years,@date)",(@date + @years*INTERVAL'1 year') +postgresql,"DATEADD(yyyy,@years,@date)",(@date + @years*INTERVAL'1 year') +postgresql,"DATEADD(year,@years,@date)",(@date + @years*INTERVAL'1 year') +postgresql,"DATEDIFF(d,@start, @end)",(CAST(@end AS DATE) - CAST(@start AS DATE)) +postgresql,"DATEDIFF(dd,@start, @end)",(CAST(@end AS DATE) - CAST(@start AS DATE)) +postgresql,"DATEDIFF(day,@start, @end)",(CAST(@end AS DATE) - CAST(@start AS DATE)) +postgresql,"CONVERT(VARCHAR,@date,112)","TO_CHAR(@date, 'YYYYMMDD')" +postgresql,GETDATE(),CURRENT_DATE +postgresql,+ '@a',|| '@a' +postgresql,'@a' +,'@a' || +postgresql,CAST(@a AS varchar(@b)) +,CAST(@a AS varchar(@b)) || +postgresql,+ CAST(@a AS varchar(@b)),|| CAST(@a AS varchar(@b)) +postgresql,CAST(@a AS varchar) +,CAST(@a AS varchar) || +postgresql,+ CAST(@a AS varchar),|| CAST(@a AS varchar) +postgresql,"DATEFROMPARTS(@year,@month,@day)","TO_DATE(TO_CHAR(@year,'0000')||'-'||TO_CHAR(@month,'00')||'-'||TO_CHAR(@day,'00'), 'YYYY-MM-DD')" +postgresql,"DATETIMEFROMPARTS(@year,@month,@day,@hour,@minute,@second,@ms)","TO_DATE(TO_CHAR(@year,'0000')||'-'||TO_CHAR(@month,'00')||'-'||TO_CHAR(@day,'00')||' '||TO_CHAR(@hour,'00')||':'||TO_CHAR(@minute,'00')||':'||TO_CHAR(@second,'00'), 'YYYY-MM-DD HH24:MI:SS')" +postgresql,YEAR(@date),EXTRACT(YEAR FROM @date) +postgresql,MONTH(@date),EXTRACT(MONTH FROM @date) +postgresql,DAY(@date),EXTRACT(DAY FROM @date) +postgresql,EOMONTH(@date),"(DATE_TRUNC('MONTH', @date) + INTERVAL '1 MONTH - 1 day')::DATE" +postgresql,STDEV(@a),STDDEV(@a) +postgresql,VAR(@a),VARIANCE(@a) +postgresql,RAND(),RANDOM() +postgresql,"HASHBYTES('MD5',@a)",MD5(@a) +postgresql,LEN(@a),CHAR_LENGTH(@a) +postgresql,"CHARINDEX(@a,@b)","STRPOS(@b,@a)" +postgresql,"LOG(@expression,@base)","(CAST((@base) AS NUMERIC),CAST((@expression) AS NUMERIC))" +postgresql,LOG(@expression),LN(CAST((@expression) AS REAL)) +postgresql,,LOG +postgresql,LOG10(@expression),"LOG(10,CAST((@expression) AS NUMERIC))" +postgresql,"ISNULL(@a,@b)","COALESCE(@a,@b)" +postgresql,ISNUMERIC(@a),(@a ~ '^([0-9]+\.?[0-9]*|\.[0-9]+)$') +postgresql,COUNT_BIG(@a),COUNT(@a) +postgresql,SQUARE(@a),((@a)*(@a)) +postgresql,NEWID(),MD5(RANDOM()::TEXT || CLOCK_TIMESTAMP()::TEXT) +postgresql,USE @schema;,SET search_path TO @schema; +postgresql,"IF OBJECT_ID('@table', 'U') IS NULL CREATE TABLE @table (@definition);",CREATE TABLE IF NOT EXISTS @table (@definition); +postgresql,"IF OBJECT_ID('@table', 'U') IS NOT NULL DROP TABLE @table;",DROP TABLE IF EXISTS @table; +postgresql,"IF OBJECT_ID('tempdb..#@table', 'U') IS NOT NULL DROP TABLE @table;",DROP TABLE IF EXISTS @table; +postgresql,.dbo.,. +postgresql,CREATE TABLE #@table (@definition),CREATE TEMP TABLE @table (@definition) +postgresql,CREATE CLUSTERED INDEX @index_name ON @table (@variable);,CREATE INDEX @index_name ON @table (@variable);\nCLUSTER @table USING @index_name; +postgresql,CREATE UNIQUE CLUSTERED INDEX @index_name ON @table (@variable);,CREATE UNIQUE INDEX @index_name ON @table (@variable);\nCLUSTER @table USING @index_name; +postgresql,PRIMARY KEY NONCLUSTERED,PRIMARY KEY +postgresql,DATETIME,TIMESTAMP +postgresql,VARCHAR(MAX),TEXT +postgresql,FLOAT,NUMERIC +postgresql,WITH @a AS @b SELECT @c INTO #@d FROM @e;,CREATE TEMP TABLE @d\nAS\nWITH @a AS @b SELECT\n@c\nFROM\n@e; +postgresql,WITH @a AS @b SELECT @c INTO @d FROM @e;,CREATE TABLE @d\nAS\nWITH @a AS @b SELECT\n@c\nFROM\n@e; +postgresql,SELECT @a INTO #@b FROM @c;,CREATE TEMP TABLE @b\nAS\nSELECT\n@a\nFROM\n@c; +postgresql,SELECT @a INTO @b FROM @c;,CREATE TABLE @b AS\nSELECT\n@a\nFROM\n@c; +postgresql,SELECT @a INTO @b;,CREATE TABLE @b AS\nSELECT\n@a; +postgresql,#, +postgresql,SELECT TOP @([0-9]+)rows @a;,SELECT @a LIMIT @rows; +postgresql,"WITH @cte AS (SELECT @s1 '@literal' @s2)","WITH @cte AS (SELECT @s1 CAST('@literal' as TEXT) @s2)" +redshift,"ROUND(@a,@b)","ROUND(CAST(@a AS FLOAT),@b)" +redshift,"ROUND(@expression,@length,@trunc)","case when @trunc = 0 then ROUND(@expression,@length) else TRUNC(@expression,@length) end" +redshift,"CONVERT(DATE, @a)","TO_DATE(@a, 'yyyymmdd')" +redshift,"DATEADD(dd,@days,@date)","DATEADD(day,@days,@date)" +redshift,"DATEADD(m,@months,@date)","DATEADD(month,@months,@date)" +redshift,"DATEADD(mm,@months,@date)","DATEADD(month,@months,@date)" +redshift,"DATEADD(yyyy,@years,@date)","DATEADD(year,@years,@date)" +redshift,"DATEADD(yy,@years,@date)","DATEADD(year,@years,@date)" +redshift,"DATEADD(qq,@n,@date)","DATEADD(quarter,@n,@date)" +redshift,"DATEADD(q,@n,@date)","DATEADD(quarter,@n,@date)" +redshift,"DATEADD(wk,@n,@date)","DATEADD(week,@n,@date)" +redshift,"DATEADD(ww,@n,@date)","DATEADD(week,@n,@date)" +redshift,"DATEADD(hh,@n,@date)","DATEADD(hour,@n,@date)" +redshift,"DATEADD(mi,@n,@date)","DATEADD(minute,@n,@date)" +redshift,"DATEADD(n,@n,@date)","DATEADD(minute,@n,@date)" +redshift,"DATEADD(ss,@n,@date)","DATEADD(second,@n,@date)" +redshift,"DATEADD(mcs,@n,@date)","DATEADD(microsecond,@n,@date)" +redshift,"DATEADD(@part,@n,@date)","DATEADD(@part,CAST(@n as int),@date)" +redshift,"DATEDIFF(dd,@start,@end)","DATEDIFF(day,@start,@end)" +redshift,"DATEDIFF(m,@start,@end)","DATEDIFF(month,@start,@end)" +redshift,"DATEDIFF(mm,@start,@end)","DATEDIFF(month,@start,@end)" +redshift,"DATEDIFF(yyyy,@start,@end)","DATEDIFF(year,@start,@end)" +redshift,"DATEDIFF(yy,@start,@end)","DATEDIFF(year,@start,@end)" +redshift,"DATEDIFF(qq,@start,@end)","DATEDIFF(quarter,@start,@end)" +redshift,"DATEDIFF(q,@start,@end)","DATEDIFF(quarter,@start,@end)" +redshift,"DATEDIFF(wk,@start,@end)","DATEDIFF(week,@start,@end)" +redshift,"DATEDIFF(ww,@start,@end)","DATEDIFF(week,@start,@end)" +redshift,"DATEDIFF(hh,@start,@end)","DATEDIFF(hour,@start,@end)" +redshift,"DATEDIFF(mi,@start,@end)","DATEDIFF(minute,@start,@end)" +redshift,"DATEDIFF(n,@start,@end)","DATEDIFF(minute,@start,@end)" +redshift,"DATEDIFF(ss,@start,@end)","DATEDIFF(second,@start,@end)" +redshift,"DATEDIFF(mcs,@start,@end)","DATEDIFF(microsecond,@start,@end)" +redshift,"DATEDIFF_BIG(dd,@start,@end)","DATEDIFF(day,@start,@end)" +redshift,"DATEDIFF_BIG(m,@start,@end)","DATEDIFF(month,@start,@end)" +redshift,"DATEDIFF_BIG(mm,@start,@end)","DATEDIFF(month,@start,@end)" +redshift,"DATEDIFF_BIG(yyyy,@start,@end)","DATEDIFF(year,@start,@end)" +redshift,"DATEDIFF_BIG(yy,@start,@end)","DATEDIFF(year,@start,@end)" +redshift,"DATEDIFF_BIG(qq,@start,@end)","DATEDIFF(quarter,@start,@end)" +redshift,"DATEDIFF_BIG(q,@start,@end)","DATEDIFF(quarter,@start,@end)" +redshift,"DATEDIFF_BIG(wk,@start,@end)","DATEDIFF(week,@start,@end)" +redshift,"DATEDIFF_BIG(ww,@start,@end)","DATEDIFF(week,@start,@end)" +redshift,"DATEDIFF_BIG(hh,@start,@end)","DATEDIFF(hour,@start,@end)" +redshift,"DATEDIFF_BIG(mi,@start,@end)","DATEDIFF(minute,@start,@end)" +redshift,"DATEDIFF_BIG(n,@start,@end)","DATEDIFF(minute,@start,@end)" +redshift,"DATEDIFF_BIG(ss,@start,@end)","DATEDIFF(second,@start,@end)" +redshift,"DATEDIFF_BIG(mcs,@start,@end)","DATEDIFF(microsecond,@start,@end)" +redshift,"DATEPART(dd,@date)","DATEPART(day,@date)" +redshift,"DATEPART(m,@date)","DATEPART(month,@date)" +redshift,"DATEPART(mm,@date)","DATEPART(month,@date)" +redshift,"DATEPART(yyyy,@date)","DATEPART(year,@date)" +redshift,"DATEPART(yy,@date)","DATEPART(year,@date)" +redshift,"DATEPART(qq,@date)","DATEPART(quarter,@date)" +redshift,"DATEPART(q,@date)","DATEPART(quarter,@date)" +redshift,"DATEPART(wk,@date)","DATEPART(week,@date)" +redshift,"DATEPART(ww,@date)","DATEPART(week,@date)" +redshift,"DATEPART(hh,@date)","DATEPART(hour,@date)" +redshift,"DATEPART(mi,@date)","DATEPART(minute,@date)" +redshift,"DATEPART(n,@date)","DATEPART(minute,@date)" +redshift,"DATEPART(ss,@date)","DATEPART(second,@date)" +redshift,"DATEPART(mcs,@date)","DATEPART(microsecond,@date)" +redshift,"CONVERT(VARCHAR,@date,112)","TO_CHAR(@date, 'YYYYMMDD')" +redshift,GETDATE(),CURRENT_DATE +redshift,+ '@a',|| '@a' +redshift,'@a' +,'@a' || +redshift,CAST(@a AS varchar(@b)) +,CAST(@a AS varchar(@b)) || +redshift,+ CAST(@a AS varchar(@b)),|| CAST(@a AS varchar(@b)) +redshift,CAST(@a AS varchar) +,CAST(@a AS varchar) || +redshift,+ CAST(@a AS varchar),|| CAST(@a AS varchar) +redshift,"DATEFROMPARTS(@year,@month,@day)","TO_DATE(TO_CHAR(@year,'0000FM')||'-'||TO_CHAR(@month,'00FM')||'-'||TO_CHAR(@day,'00FM'), 'YYYY-MM-DD')" +redshift,"DATETIMEFROMPARTS(@year,@month,@day,@hour,@minute,@second,@ms)","CAST(TO_CHAR(@year,'0000FM')||'-'||TO_CHAR(@month,'00FM')||'-'||TO_CHAR(@day,'00FM')||' '||TO_CHAR(@hour,'00FM')||':'||TO_CHAR(@minute,'00FM')||':'||TO_CHAR(@second,'00FM')||'.'||TO_CHAR(@ms,'000FM') as TIMESTAMP)" +redshift,YEAR(@date),EXTRACT(YEAR FROM @date) +redshift,MONTH(@date),EXTRACT(MONTH FROM @date) +redshift,DAY(@date),EXTRACT(DAY FROM @date) +redshift,EOMONTH(@date),LAST_DAY(@date) +redshift,VAR(@a),VARIANCE(@a) +redshift,STDEV(@a),STDDEV(@a) +redshift,RAND(),RANDOM() +redshift,"HASHBYTES('MD5',@a)",MD5(@a) +redshift,LEN(@a),CHAR_LENGTH(@a) +redshift,"LOG(@expression,@base)",(LN(CAST((@expression) AS REAL))/LN(CAST((@base) AS REAL))) +redshift,LOG(@expression),LN(CAST((@expression) AS REAL)) +redshift,LOG10(@expression),LOG(CAST((@expression) AS REAL)) +redshift,"ISNULL(@a,@b)","COALESCE(@a,@b)" +redshift,COUNT_BIG(@a),COUNT(@a) +redshift,SQUARE(@a),((@a) * (@a)) +redshift,TEXT,VARCHAR(max) +redshift,NTEXT,VARCHAR(max) +redshift,NEWID(),MD5(RANDOM()::TEXT || GETDATE()::TEXT) +redshift,USE @schema;,SET search_path TO @schema; +redshift,"IF OBJECT_ID('@table', 'U') IS NULL CREATE TABLE @table (@definition);",CREATE TABLE IF NOT EXISTS @table (@definition); +redshift,"IF OBJECT_ID('@table', 'U') IS NOT NULL DROP TABLE @table;",DROP TABLE IF EXISTS @table; +redshift,"IF OBJECT_ID('tempdb..#@table', 'U') IS NOT NULL DROP TABLE @table;","DROP TABLE IF EXISTS #@table;" +redshift,.dbo.,. +redshift,"HINT DISTRIBUTE_ON_KEY(@key) @hint CREATE TABLE @table (@definition);",HINT DISTRIBUTE_ON_KEY(@key) @hint\nCREATE TABLE @table (@definition)\nDISTKEY(@key); +redshift,"HINT @hint SORT_ON_KEY(@type:@key) CREATE TABLE @table (@definition) @options;",HINT @hint SORT_ON_KEY(@type:@key)\nCREATE TABLE @table (@definition)\n@options\n@type SORTKEY(@key); +redshift,"CREATE TABLE @table (@a1 person_id @a2);",CREATE TABLE @table (@a1 person_id @a2)\nDISTKEY(person_id); +redshift,"CREATE TABLE @table (@a1 subject_id @a2);",CREATE TABLE @table (@a1 subject_id @a2)\nDISTKEY(subject_id); +redshift,"CREATE TABLE @table (@a1 analysis_id @a2);",CREATE TABLE @table (@a1 analysis_id @a2)\nDISTKEY(analysis_id); +redshift,"CREATE TABLE @table (@definition);",CREATE TABLE @table (@definition)\nDISTSTYLE ALL; +redshift,HINT DISTRIBUTE_ON_KEY(@key) WITH @a AS @b SELECT @c INTO @d FROM @e;,HINT DISTRIBUTE_ON_KEY(@key)\nCREATE TABLE @d\nDISTKEY(@key)\nAS\nWITH @a AS @b SELECT\n@c\nFROM\n@e; +redshift,HINT SORT_ON_KEY(@type:@sortkey) WITH @a AS @b SELECT @c INTO @d FROM @e;,HINT SORT_ON_KEY(@type:@sortkey)\nCREATE TABLE @d\n@type SORTKEY(@sortkey)\nAS\nWITH @a AS @b SELECT\n@c\nFROM\n@e; +redshift,HINT DISTRIBUTE_ON_KEY(@key) SORT_ON_KEY(@type:@sortkey) WITH @a AS @b SELECT @c INTO @d FROM @e;,HINT DISTRIBUTE_ON_KEY(@key) SORT_ON_KEY(@type:@sortkey)\nCREATE TABLE @d\nDISTKEY(@key)\n@type SORTKEY(@sortkey)\nAS\nWITH @a AS @b SELECT\n@c\nFROM\n@e; +redshift,WITH @a AS @b SELECT @c1 person_id as @(\w+\b)key @c2 INTO @d FROM @e;,CREATE TABLE @d\nDISTKEY(@key)\nAS\nWITH\n@a\nAS\n@b\nSELECT\n@c1 person_id as @key @c2\nFROM\n@e; +redshift,WITH @a AS @b SELECT @c1 person_id @(\w+\b)key @c2 INTO @d FROM @e;,CREATE TABLE @d\nDISTKEY(@key)\nAS\nWITH\n@a\nAS\n@b\nSELECT\n@c1 person_id @key @c2\nFROM\n@e; +redshift,WITH @a AS @b SELECT @c1 person_id @c2 INTO @d FROM @e;,CREATE TABLE @d\nDISTKEY(person_id)\nAS\nWITH\n@a\nAS\n@b\nSELECT\n@c1 person_id @c2\nFROM\n@e; +redshift,WITH @a AS @b SELECT @c1 subject_id as @(\w+\b)key @c2 INTO @d FROM @e;,CREATE TABLE @d\nDISTKEY(@key)\nAS\nWITH\n@a\nAS\n@b\nSELECT\n@c1 subject_id as @key @c2\nFROM\n@e; +redshift,WITH @a AS @b SELECT @c1 subject_id @(\w+\b)key @c2 INTO @d FROM @e;,CREATE TABLE @d\nDISTKEY(@key)\nAS\nWITH\n@a\nAS\n@b\nSELECT\n@c1 subject_id @key @c2\nFROM\n@e; +redshift,WITH @a AS @b SELECT @c1 subject_id @c2 INTO @d FROM @e;,CREATE TABLE @d\nDISTKEY(subject_id)\nAS\nWITH\n@a\nAS\n@b\nSELECT\n@c1 subject_id @c2\nFROM\n@e; +redshift,WITH @a AS @b SELECT @c1 analysis_id as @(\w+\b)key @c2 INTO @d FROM @e;,CREATE TABLE @d\nDISTKEY(@key)\nAS\nWITH\n@a\nAS\n@b\nSELECT\n@c1 analysis_id as @key @c2\nFROM\n@e; +redshift,WITH @a AS @b SELECT @c1 analysis_id @(\w+\b)key @c2 INTO @d FROM @e;,CREATE TABLE @d\nDISTKEY(@key)\nAS\nWITH\n@a\nAS\n@b\nSELECT\n@c1 analysis_id @key @c2\nFROM\n@e; +redshift,WITH @a AS @b SELECT @c1 analysis_id @c2 INTO @d FROM @e;,CREATE TABLE @d\nDISTKEY(analysis_id)\nAS\nWITH\n@a\nAS\n@b\nSELECT\n@c1 analysis_id @c2\nFROM\n@e; +redshift,WITH @a AS @b SELECT @c INTO @d FROM @e;,CREATE TABLE @d DISTSTYLE ALL\nAS\nWITH\n@a\nAS\n@b\nSELECT\n@c\nFROM\n@e; +redshift,HINT DISTRIBUTE_ON_KEY(@key) SELECT @a INTO @b FROM @c;,HINT DISTRIBUTE_ON_KEY(@key) \nCREATE TABLE @b\nDISTKEY(@key)\nAS\nSELECT\n@a\nFROM\n@c; +redshift,HINT SORT_ON_KEY(@type:@sortkey) SELECT @a INTO @b FROM @c;,HINT SORT_ON_KEY(@type:@sortkey)\nCREATE TABLE @b\n@type SORTKEY(@sortkey)\nAS\nSELECT\n@a\nFROM\n@c; +redshift,HINT DISTRIBUTE_ON_KEY(@key) SORT_ON_KEY(@type:@sortkey) SELECT @a INTO @b FROM @c;,HINT DISTRIBUTE_ON_KEY(@key) SORT_ON_KEY(@type:@sortkey)\nCREATE TABLE @b\nDISTKEY(@key)\n@type SORTKEY(@sortkey)\nAS\nSELECT\n@a\nFROM\n@c; +redshift,SELECT @a1 person_id as @(\w+\b)key @a2 INTO @b FROM @c;,CREATE TABLE @b\nDISTKEY(@key)\nAS\nSELECT\n@a1 person_id as @key @a2\nFROM\n@c; +redshift,SELECT @a1 person_id @(\w+\b)key @a2 INTO @b FROM @c;,CREATE TABLE @b\nDISTKEY(@key)\nAS\nSELECT\n@a1 person_id @key @a2\nFROM\n@c; +redshift,SELECT @a1 person_id @a2 INTO @b FROM @c;,CREATE TABLE @b\nDISTKEY(person_id)\nAS\nSELECT\n@a1 person_id @a2\nFROM\n@c; +redshift,SELECT @a1 subject_id as @(\w+\b)key @a2 INTO @b FROM @c;,CREATE TABLE @b\nDISTKEY(@key)\nAS\nSELECT\n@a1 subject_id as @key @a2\nFROM\n@c; +redshift,SELECT @a1 subject_id @(\w+\b)key @a2 INTO @b FROM @c;,CREATE TABLE @b\nDISTKEY(@key)\nAS\nSELECT\n@a1 subject_id @key @a2\nFROM\n@c; +redshift,SELECT @a1 subject_id @a2 INTO @b FROM @c;,CREATE TABLE @b\nDISTKEY(subject_id)\nAS\nSELECT\n@a1 subject_id @a2\nFROM\n@c; +redshift,SELECT @a1 analysis_id as @(\w+\b)key @a2 INTO @b FROM @c;,CREATE TABLE @b\nDISTKEY(@key)\nAS\nSELECT\n@a1 analysis_id as @key @a2\nFROM\n@c; +redshift,SELECT @a1 analysis_id @(\w+\b)key @a2 INTO @b FROM @c;,CREATE TABLE @b\nDISTKEY(@key)\nAS\nSELECT\n@a1 analysis_id @key @a2\nFROM\n@c; +redshift,SELECT @a1 analysis_id @a2 INTO @b FROM @c;,CREATE TABLE @b\nDISTKEY(analysis_id)\nAS\nSELECT\n@a1 analysis_id @a2\nFROM\n@c; +redshift,SELECT @a INTO @b FROM @c;,CREATE TABLE @b DISTSTYLE ALL\nAS\nSELECT\n@a\nFROM\n@c; +redshift,SELECT @a INTO @b;,CREATE TABLE @b DISTSTYLE ALL\nAS\nSELECT\n@a; +redshift,[ person_id ],[person_id] +redshift,[ subject_id ],[subject_id] +redshift,[ analysis_id ],[analysis_id] +redshift,PRIMARY KEY NONCLUSTERED,PRIMARY KEY +redshift,DATETIME,TIMESTAMP +redshift,SELECT DISTINCT TOP @([0-9]+)rows,SELECT TOP @rows DISTINCT +redshift,BIT,BOOLEAN +redshift,MONEY,"DECIMAL(19, 4)" +redshift,SMALLMONEY,"DECIMAL(10, 4)" +redshift,TINYINT,SMALLINT +redshift,FLOAT(@s),FLOAT +redshift,DATETIME2(@p),TIMESTAMP +redshift,DATETIME2,TIMESTAMP +redshift,DATETIME,TIMESTAMP +redshift,DATETIMEOFFSET(@p),TIMESTAMPTZ +redshift,DATETIMEOFFSET,TIMESTAMPTZ +redshift,SMALLDATETIME,TIMESTAMP +redshift,UNIQUEIDENTIFIER,CHAR(36) +redshift,STDEVP(@a),STDDEV_POP(@a) +redshift,VARP(@a),VAR_POP(@a) +redshift,"DATETIME2FROMPARTS(@year,@month,@day,@hour,@minute,@seconds,0,0)","CAST(TO_CHAR(@year,'0000FM')||'-'||TO_CHAR(@month,'00FM')||'-'||TO_CHAR(@day,'00FM')||' '||TO_CHAR(@hour,'00FM')||':'||TO_CHAR(@minute,'00FM')||':'||TO_CHAR(@seconds,'00FM') as TIMESTAMP)" +redshift,"DATETIME2FROMPARTS(@year,@month,@day,@hour,@minute,@seconds,@fractions,@precision)","CAST(TO_CHAR(@year,'0000FM')||'-'||TO_CHAR(@month,'00FM')||'-'||TO_CHAR(@day,'00FM')||' '||TO_CHAR(@hour,'00FM')||':'||TO_CHAR(@minute,'00FM')||':'||TO_CHAR(@seconds,'00FM')||'.'||TO_CHAR(@fractions,repeat('0', @precision) || 'FM') as TIMESTAMP)" +redshift,"DATETIMEOFFSETFROMPARTS (@year,@month,@day,@hour,@minute,@seconds,0,@h_offset,@m_offset,0 )","CAST(TO_CHAR(@year,'0000FM')||'-'||TO_CHAR(@month,'00FM')||'-'||TO_CHAR(@day,'00FM')||' '||TO_CHAR(@hour,'00FM')||':'||TO_CHAR(@minute,'00FM')||':'||TO_CHAR(@seconds,'00FM')||case when @h_offset >= 0 then '+' else '-' end ||TO_CHAR(ABS(@h_offset),'00FM')||':'||TO_CHAR(ABS(@m_offset),'00FM') as TIMESTAMPTZ)" +redshift,"DATETIMEOFFSETFROMPARTS (@year,@month,@day,@hour,@minute,@seconds,@fractions,@h_offset,@m_offset,@precision )","CAST(TO_CHAR(@year,'0000FM')||'-'||TO_CHAR(@month,'00FM')||'-'||TO_CHAR(@day,'00FM')||' '||TO_CHAR(@hour,'00FM')||':'||TO_CHAR(@minute,'00FM')||':'||TO_CHAR(@seconds,'00FM')||'.'||TO_CHAR(@fractions,repeat('0',@precision) || 'FM')||case when @h_offset >= 0 then '+' else '-' end ||TO_CHAR(ABS(@h_offset),'00FM')||':'||TO_CHAR(ABS(@m_offset),'00FM') as TIMESTAMPTZ)" +redshift,GETUTCDATE(),CURRENT_TIMESTAMP +redshift,"SMALLDATETIMEFROMPARTS(@year,@month,@day,@hour,@minute )","CAST(TO_CHAR(@year,'0000FM')||'-'||TO_CHAR(@month,'00FM')||'-'||TO_CHAR(@day,'00FM')||' '||TO_CHAR(@hour,'00FM')||':'||TO_CHAR(@minute,'00FM') as TIMESTAMP)" +redshift,SYSUTCDATETIME(),CURRENT_TIMESTAMP +redshift,"TODATETIMEOFFSET(@expression,@timezone)","CAST(TO_CHAR(CAST(@expression as TIMESTAMP), 'YYYY-MM-DD HH24:MI:SS.US') ||@timezone as TIMESTAMPTZ)" +redshift,"ATN2(@a,@b)","ATAN2(@a,@b)" +redshift,"CHARINDEX(@expression,@in,@start)","case when CHARINDEX(@expression, SUBSTRING(@in,@start)) > 0 then (CHARINDEX(@expression, SUBSTRING(@in,@start)) +@start - 1) else 0 end" +redshift,QUOTENAME(@a),QUOTE_IDENT(@a) +redshift,"SPACE(@n)","REPEAT(' ',@n)" +redshift,"STUFF(@expression,@start,@length,@replace)","SUBSTRING(@expression, 0,@start)||@replace||SUBSTRING(@expression,@start +@length)" +redshift,"CONCAT(@a,@b,@tail)","CONCAT(@a,CONCAT(@b,@tail))" +redshift,"ISDATE(@s)","REGEXP_INSTR(@s, '^(\\d{4}[/\-]?[01]\\d[/\-]?[0123]\\d)([ T]([0-1][0-9]|[2][0-3]):([0-5][0-9])(:[0-5][0-9](.\\d+)?)?)?$')" +redshift,"ISNUMERIC(@s)","REGEXP_INSTR(@s, '^[\-\+]?(\\d*\\.)?\\d+([Ee][\-\+]?\\d+)?$')" +redshift,"PATINDEX(@pattern,@expression)","REGEXP_INSTR(@expression, case when LEFT(@pattern,1)<>'%' and RIGHT(@pattern,1)='%' then '^' else '' end||TRIM('%' FROM REPLACE(@pattern,'_','.'))||case when LEFT(@pattern,1)='%' and RIGHT(@pattern,1)<>'%' then '$' else '' end)" +redshift,"WITH @cte AS (SELECT @s1 '@literal' @s2)","WITH @cte AS (SELECT @s1 CAST('@literal' as TEXT) @s2)" +redshift,^,# +pdw,VARCHAR(MAX),VARCHAR(1000) +pdw,HINT DISTRIBUTE_ON_KEY(@key) @hint WITH @a AS @b SELECT @c INTO @d FROM @e;,HINT DISTRIBUTE_ON_KEY(@key) @hint\nCREATE TABLE @d WITH (DISTRIBUTION = HASH(@key))\nAS\nWITH @a AS @b SELECT\n@c\nFROM\n@e; +pdw,"WITH @a AS @b SELECT @c1 subject_id, @c2 INTO @d FROM @e;","CREATE TABLE @d WITH (DISTRIBUTION = HASH(subject_id))\nAS\nWITH @a AS @b SELECT\n@c1 subject_id, @c2\nFROM\n@e;" +pdw,"WITH @a AS @b SELECT @c1 person_id, @c2 INTO @d FROM @e;","CREATE TABLE @d WITH (DISTRIBUTION = HASH(person_id))\nAS\nWITH @a AS @b SELECT\n@c1 person_id, @c2\nFROM\n@e;" +pdw,"WITH @a AS @b SELECT @c1 analysis_id, @c2 INTO @d FROM @e;","CREATE TABLE @d WITH (DISTRIBUTION = HASH(analysis_id))\nAS\nWITH @a AS @b SELECT\n@c1 analysis_id, @c2\nFROM\n@e;" +pdw,WITH @a AS @b SELECT @c INTO @d FROM @e;,CREATE TABLE @d WITH (DISTRIBUTION = REPLICATE)\nAS\nWITH @a AS @b SELECT\n@c\nFROM\n@e; +pdw,HINT DISTRIBUTE_ON_KEY(@key) @hint SELECT @a INTO @b FROM @c;,HINT DISTRIBUTE_ON_KEY(@key) @hint\nCREATE TABLE @b WITH (DISTRIBUTION = HASH(@key))\nAS\nSELECT\n@a\nFROM\n@c; +pdw,"SELECT @a1 subject_id, @a2 INTO @b FROM @c;","CREATE TABLE @b WITH (DISTRIBUTION = HASH(subject_id))\nAS\nSELECT\n@a1 subject_id, @a2\nFROM\n@c;" +pdw,"SELECT @a1 person_id, @a2 INTO @b FROM @c;","CREATE TABLE @b WITH (DISTRIBUTION = HASH(person_id))\nAS\nSELECT\n@a1 person_id, @a2\nFROM\n@c;" +pdw,"SELECT @a1 analysis_id, @a2 INTO @b FROM @c;","CREATE TABLE @b WITH (DISTRIBUTION = HASH(analysis_id))\nAS\nSELECT\n@a1 analysis_id, @a2\nFROM\n@c;" +pdw,SELECT @a INTO @b FROM @c;,CREATE TABLE @b WITH (DISTRIBUTION = REPLICATE)\nAS\nSELECT\n@a\nFROM\n@c; +pdw,SELECT @a INTO @b;,CREATE TABLE @b WITH (DISTRIBUTION = REPLICATE)\nAS\nSELECT\n@a; +pdw,CREATE TABLE #@a WITH (DISTRIBUTION = @b) AS,"CREATE TABLE #@a WITH (LOCATION = USER_DB, DISTRIBUTION = @b) AS" +pdw,HINT DISTRIBUTE_ON_KEY(@key) @hint CREATE TABLE @table (@definition);,HINT DISTRIBUTE_ON_KEY(@key) @hint\nCREATE TABLE @table (@definition)\nWITH (DISTRIBUTION = HASH(@key)); +pdw,CREATE TABLE @table (@definition_part1 subject_id @definition_part2);,CREATE TABLE @table (@definition_part1 subject_id @definition_part2)\nWITH (DISTRIBUTION = HASH(subject_id)); +pdw,CREATE TABLE @table (@definition_part1 person_id @definition_part2);,CREATE TABLE @table (@definition_part1 person_id @definition_part2)\nWITH (DISTRIBUTION = HASH(person_id)); +pdw,CREATE TABLE @table (@definition_part1 analysis_id @definition_part2);,CREATE TABLE @table (@definition_part1 analysis_id @definition_part2)\nWITH (DISTRIBUTION = HASH(analysis_id)); +pdw,CREATE TABLE @table (@definition);,CREATE TABLE @table (@definition)\nWITH (DISTRIBUTION = REPLICATE); +pdw,CREATE TABLE #@table (@definition) WITH (DISTRIBUTION = @distribution);,"CREATE TABLE #@table (@definition)\nWITH (LOCATION = USER_DB, DISTRIBUTION = @distribution);" +pdw,[ person_id ],[person_id] +pdw,[ subject_id ],[subject_id] +pdw,[ analysis_id ],[analysis_id] +pdw,TRUNCATE TABLE ,IF XACT_STATE() = 1 COMMIT; TR*NC*T* TABLE +pdw,DROP TABLE ,IF XACT_STATE() = 1 COMMIT; DR*P TABLE +pdw,CREATE TABLE ,IF XACT_STATE() = 1 COMMIT; CR**T* TABLE +pdw,TR*NC*T*,TRUNCATE +pdw,DR*P,DROP +pdw,CR**T*,CREATE +pdw,IF OBJECT_ID(@a) IS NOT NULL IF XACT_STATE() = 1 COMMIT;,IF XACT_STATE() = 1 COMMIT; IF OBJECT_ID(@a) IS NOT NULL +impala,"CHARINDEX(@a,@b)","INSTR(@b,@a)" +impala,COUNT_BIG(@a),COUNT(@a) +impala,"LEFT(@str,@chars)","SUBSTR(@str,1,@chars)" +impala,LEN(@a),LENGTH(@a) +impala,LOG(@expression),LN(@expression) +impala,NEWID(),UUID() +impala,"RIGHT(@str,@chars)","SUBSTR(@str,-@chars)" +impala,"ROUND(@a,@b)","ROUND(CAST(@a AS DOUBLE),@b)" +impala,SQUARE(@a),((@a)*(@a)) +impala,STDEV(@a),STDDEV(@a) +impala,VAR(@a),VARIANCE(@a) +impala,"DATEADD(d,@days,CAST(@date AS DATE))","DATE_ADD(@date, @days)" +impala,"DATEADD(dd,@days,CAST(@date AS DATE))","DATE_ADD(@date, @days)" +impala,"DATEADD(day,@days,CAST(@date AS DATE))","DATE_ADD(@date, @days)" +impala,"DATEADD(month,@months,CAST(@date AS DATE))","ADD_MONTHS(@date, @months)" +impala,"DATEADD(mm,@months,CAST(@date AS DATE))","ADD_MONTHS(@date, @months)" +impala,"DATEADD(m,@months,CAST(@date AS DATE))","ADD_MONTHS(@date, @months)" +impala,"DATEADD(year,@years,CAST(@date AS DATE))","ADD_MONTHS(@date, 12 * @years)" +impala,"DATEADD(yyyy,@years,CAST(@date AS DATE))","ADD_MONTHS(@date, 12 * @years)" +impala,"DATEADD(yy,@years,CAST(@date AS DATE))","ADD_MONTHS(@date, 12 * @years)" +impala,"DATEADD(d,@days,@date)","DATE_ADD(CAST(@date AS DATE), @days)" +impala,"DATEADD(dd,@days,@date)","DATE_ADD(CAST(@date AS DATE), @days)" +impala,"DATEADD(day,@days,@date)","DATE_ADD(CAST(@date AS DATE), @days)" +impala,"DATEADD(month,@months,@date)","ADD_MONTHS(CAST(@date AS DATE), @months)" +impala,"DATEADD(mm,@months,@date)","ADD_MONTHS(CAST(@date AS DATE), @months)" +impala,"DATEADD(m,@months,@date)","ADD_MONTHS(CAST(@date AS DATE), @months)" +impala,"DATEADD(year,@years,@date)","ADD_MONTHS(CAST(@date AS DATE), 12 * @years)" +impala,"DATEADD(yyyy,@years,@date)","ADD_MONTHS(CAST(@date AS DATE), 12 * @years)" +impala,"DATEADD(yy,@years,@date)","ADD_MONTHS(CAST(@date AS DATE), 12 * @years)" +impala,"DATEDIFF(d,@start, @end)","DATEDIFF(CAST(@end AS DATE), CAST(@start AS DATE))" +impala,"DATEDIFF(dd,@start, @end)","DATEDIFF(CAST(@end AS DATE), CAST(@start AS DATE))" +impala,"DATEDIFF(day,@start, @end)","DATEDIFF(CAST(@end AS DATE), CAST(@start AS DATE))" +impala,DAY(@date),DAY(CAST(@date AS DATE)) +impala,GETDATE(),NOW() +impala,MONTH(@date),MONTH(CAST(@date AS DATE)) +impala,YEAR(@date),YEAR(CAST(@date AS DATE)) +impala,CAST(@a AS DATE),"CASE TYPEOF(@a) WHEN 'TIMESTAMP' THEN CAST(@a AS TIMESTAMP) ELSE TO_UTC_TIMESTAMP(CONCAT_WS('-', SUBSTR(CAST(@a AS STRING), 1, 4), SUBSTR(CAST(@a AS STRING), 5, 2), SUBSTR(CAST(@a AS STRING), 7, 2)), 'UTC') END" +impala,"IF OBJECT_ID('@table', 'U') IS NULL CREATE TABLE @table (@definition);",CREATE TABLE IF NOT EXISTS @table (@definition); +impala,"IF OBJECT_ID('@table', 'U') IS NOT NULL DROP TABLE @table;",DROP TABLE IF EXISTS @table; +impala,WITH @a AS @b SELECT @c INTO @d FROM @e;,CREATE TABLE @d\nAS\nWITH @a AS @b SELECT\n@c\nFROM\n@e; +impala,SELECT @a INTO @b FROM @c;,CREATE TABLE @b AS\nSELECT\n@a\nFROM\n@c; +impala,SELECT @a INTO @b;,CREATE TABLE @b AS\nSELECT\n@a; +impala,SELECT DISTINCT @a FROM @b INTERSECT SELECT DISTINCT @a FROM @c;,SELECT t1.@a FROM (SELECT DISTINCT @a FROM @b UNION ALL SELECT DISTINCT @a FROM @c) AS t1 GROUP BY @a HAVING COUNT(*) >= 2; +impala,(SELECT DISTINCT @a FROM @b INTERSECT SELECT DISTINCT @a FROM @c),(SELECT t1.@a FROM (SELECT DISTINCT @a FROM @b UNION ALL SELECT DISTINCT @a FROM @c) AS t1 GROUP BY @a HAVING COUNT(*) >= 2) +impala,DELETE FROM @a;,/* DELETE FROM @a; */ +impala,DELETE FROM @a WHERE @b;,/* DELETE FROM @a WHERE @b; */ +impala,.dbo.,. +impala,##, +impala,#,%temp_prefix%%session_id% +impala,,## +impala,.location,.`location` +impala,SELECT TOP @([0-9]+)rows @a;,SELECT @a LIMIT @rows; +netezza,"ROUND(@a,@b)","ROUND(CAST(@a AS NUMERIC),@b)" +netezza,CAST(@a AS DATE),"TO_DATE(@a, 'yyyymmdd')" +netezza,CAST(@a AS INT),CAST(@a AS INTEGER) +netezza,CAST(@a AS VARCHAR),CAST(@a AS VARCHAR(1000)) +netezza,"DATEADD(d,@days,@date)",(@date + @days) +netezza,"DATEADD(dd,@days,@date)",(@date + @days) +netezza,"DATEADD(day,@days,@date)",(@date + @days) +netezza,"DATEADD(m,@months,@date)",CAST((@date + @months*INTERVAL'1 month') AS DATE) +netezza,"DATEADD(mm,@months,@date)",CAST((@date + @months*INTERVAL'1 month') AS DATE) +netezza,"DATEADD(month,@months,@date)",CAST((@date + @months*INTERVAL'1 month') AS DATE) +netezza,"DATEADD(yy,@years,@date)",CAST((@date + @years*INTERVAL'1 year') AS DATE) +netezza,"DATEADD(yyyy,@years,@date)",CAST((@date + @years*INTERVAL'1 year') AS DATE) +netezza,"DATEADD(year,@years,@date)",CAST((@date + @years*INTERVAL'1 year') AS DATE) +netezza,"DATEDIFF(d,@start, @end)",(CAST(@end AS DATE) - CAST(@start AS DATE)) +netezza,"DATEDIFF(dd,@start, @end)",(CAST(@end AS DATE) - CAST(@start AS DATE)) +netezza,"DATEDIFF(day,@start, @end)",(CAST(@end AS DATE) - CAST(@start AS DATE)) +netezza,GETDATE(),CURRENT_DATE +netezza,+ '@a',|| '@a' +netezza,'@a' +,'@a' || +netezza,YEAR(@variable),"DATE_PART('YEAR', @variable)" +netezza,MONTH(@variable),"DATE_PART('MONTH', @variable)" +netezza,CAST(@a AS varchar(@b)) +,CAST(@a AS varchar(@b)) || +netezza,+ CAST(@a AS varchar(@b)),|| CAST(@a AS varchar(@b)) +netezza,YEAR(@date),EXTRACT(YEAR FROM @date) +netezza,MONTH(@date),EXTRACT(MONTH FROM @date) +netezza,STDEV(@a),STDDEV(@a) +netezza,LEN(@a),CHAR_LENGTH(@a) +netezza,"LOG(@expression,@base)",(LN(@expression)/LN(@base)) +netezza,LOG(@expression),LN(@expression) +netezza,LOG10(@expression),LOG(@expression) +netezza,"ISNULL(@a,@b)","COALESCE(@a,@b)" +netezza,COUNT_BIG(@a),COUNT(@a) +netezza,USE @schema;,SET search_path TO @schema; +netezza,"IF OBJECT_ID('@table', 'U') IS NOT NULL DROP TABLE @table;",DROP TABLE @table IF EXISTS; +netezza,.dbo.,. +netezza,CREATE TABLE #@table (@definition),CREATE TEMP TABLE @table (@definition) +netezza,CREATE CLUSTERED INDEX @index_name ON @table (@variable);,CREATE INDEX @index_name ON @table (@variable);\nCLUSTER @table USING @index_name; +netezza,CREATE UNIQUE CLUSTERED INDEX @index_name ON @table (@variable);,CREATE UNIQUE INDEX @index_name ON @table (@variable);\nCLUSTER @table USING @index_name; +netezza,PRIMARY KEY NONCLUSTERED,PRIMARY KEY +netezza,VARCHAR(MAX),VARCHAR(1000) +netezza,FLOAT,NUMERIC +netezza,WITH @a AS @b SELECT @c INTO #@d FROM @e;,CREATE TEMP TABLE @d\nAS\nWITH @a AS @b SELECT\n@c\nFROM\n@e; +netezza,WITH @a AS @b SELECT @c INTO @d FROM @e;,CREATE TABLE @d\nAS\nWITH @a AS @b SELECT\n@c\nFROM\n@e; +netezza,SELECT @a INTO #@b FROM @c;,CREATE TEMP TABLE @b\nAS\nSELECT\n@a\nFROM\n@c; +netezza,SELECT @a INTO @b FROM @c;,CREATE TABLE @b AS\nSELECT\n@a\nFROM\n@c; +netezza,#, +netezza,"LEFT(@variable,@b)","STRLEFT(@variable,@b)" +netezza,"RIGHT(@variable,@b)","STRRIGHT(@variable,@b)" +netezza,SELECT TOP @([0-9]+)rows @a;,SELECT @a LIMIT @rows; +bigquery,"DATEDIFF(d,@start, @end)","DATE_DIFF(cast(@end as date), cast(@start as date), DAY)" +bigquery,"DATEDIFF(dd,@start, @end)","DATE_DIFF(cast(@end as date), cast(@start as date), DAY)" +bigquery,"DATEDIFF(day,@start, @end)","DATE_DIFF(cast(@end as date), cast(@start as date), DAY)" +bigquery,"DATEADD(d,@days,@date)","DATE_ADD(cast(@date as date), interval @days DAY)" +bigquery,"DATEADD(dd,@days,@date)","DATE_ADD(cast(@date as date), interval @days DAY)" +bigquery,"DATEADD(day,@days,@date)","DATE_ADD(cast(@date as date), interval @days DAY)" +bigquery,"DATEADD(m,@months,@date)","DATE_ADD(cast(@date as date), interval @months MONTH)" +bigquery,"DATEADD(mm,@months,@date)","DATE_ADD(cast(@date as date), interval @months MONTH)" +bigquery,"DATEADD(month,@months,@date)","DATE_ADD(cast(@date as date), interval @months MONTH)" +bigquery,"GETDATE()","CURRENT_DATE()" +bigquery,"STDEV(@a)","STDDEV(@a)" +bigquery,"HASHBYTES('MD5',@a)","SHA1(@a)" +bigquery,"LEN(@a)","LENGTH(@a)" +bigquery,"COUNT_BIG(@a)","COUNT(@a)" +bigquery,"CAST(@a as:string)","CAST(@a as string)" +bigquery,"CAST(@a as:integer)","CAST(@a as int64)" +bigquery,"CAST(@a as:float)","CAST(@a as float64)" +bigquery,"IF OBJECT_ID('@table', 'U') IS NOT NULL DROP TABLE @table;",DROP TABLE IF EXISTS @table; +bigquery,CAST(@a AS varchar(@b)),CAST(@a AS STRING) +bigquery,"WITH @a INTO #@b FROM","INTO #@b WITH @a FROM" +bigquery,"SELECT @a INTO #@b FROM","INTO #@b SELECT @a FROM" +bigquery,#,temp. +bigquery,"LEFT(@str,@chars)","SUBSTR(@str,0,@chars)" +bigquery,"RIGHT(@str,@chars)","SUBSTR(@str,-@chars)" +bigquery,"cast(@a as float)","cast(@a as float64)" +bigquery,"cast(@a as bigint)","cast(@a as int64)" +bigquery,"cast(@a as int)","cast(@a as int64)" +bigquery,"cast(@a as varchar)","cast(@a as string)" +bigquery,date(@a),cast(@a as date) +bigquery,"cast(concat(@a) as date)","parse_date('%Y%m%d', concat(@a))" +bigquery,"YEAR(@date)","EXTRACT(YEAR from @date)" +bigquery,"MONTH(@date)","EXTRACT(MONTH from @date)" +bigquery,"DAY(@date)","EXTRACT(DAY from @date)" +bigquery,"union select","union distinct select" +bigquery,SELECT DISTINCT @a FROM @b INTERSECT SELECT DISTINCT @a FROM @c;,SELECT t1.@a FROM (SELECT DISTINCT @a FROM @b UNION ALL SELECT DISTINCT @a FROM @c) AS t1 GROUP BY @a HAVING COUNT(*) >= 2; +bigquery,(SELECT DISTINCT @a FROM @b INTERSECT SELECT DISTINCT @a FROM @c),(SELECT t1.@a FROM (SELECT DISTINCT @a FROM @b UNION ALL SELECT DISTINCT @a FROM @c) AS t1 GROUP BY @a HAVING COUNT(*) >= 2) +bigquery,"ISNULL(@a,@b)","IFNULL(@a,@b)" diff --git a/inst/doc/UsingSqlRender.pdf b/inst/doc/UsingSqlRender.pdf index 4c59d120..1ce8ac5b 100644 Binary files a/inst/doc/UsingSqlRender.pdf and b/inst/doc/UsingSqlRender.pdf differ diff --git a/inst/java/SqlRender.jar b/inst/java/SqlRender.jar index 032afbad..2f0c6139 100644 Binary files a/inst/java/SqlRender.jar and b/inst/java/SqlRender.jar differ diff --git a/inst/shinyApps/SqlDeveloper/SqlDeveloper.Rproj b/inst/shinyApps/SqlDeveloper/SqlDeveloper.Rproj new file mode 100644 index 00000000..8e3c2ebc --- /dev/null +++ b/inst/shinyApps/SqlDeveloper/SqlDeveloper.Rproj @@ -0,0 +1,13 @@ +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX diff --git a/inst/shinyApps/SqlDeveloper/server.R b/inst/shinyApps/SqlDeveloper/server.R new file mode 100644 index 00000000..cfffdc7f --- /dev/null +++ b/inst/shinyApps/SqlDeveloper/server.R @@ -0,0 +1,83 @@ +library(shiny) +library(SqlRender) + +shinyServer(function(input, output, session) { + + # cache <- reactiveValues(target = "", + # clicks = 0, + # parameters = NULL) + + parameters <- reactive({ + params <- regmatches(input$source, gregexpr("@[a-zA-Z0-9_]+", input$source))[[1]] + params <- unique(params) + params <- params[order(params)] + params <- substr(params, 2, nchar(params)) + return(params) + }) + + output$target <- renderText({ + # if (!input$continuous && (input$renderTranslate == cache$clicks)) { + # return(cache$target) + # } else { + # print(paste("continuous: ", input$continuous, ", renderTranslate: ", input$renderTranslate)) + parameterValues <- list() + for (param in parameters()) { + value <- input[[param]] + if (!is.null(value)) { + parameterValues[[param]] <- value + } + } + sql <- do.call("renderSql", append(input$source, parameterValues))$sql + warningString <- c() + handleWarning <- function(e) { + output$warnings <- e$message + } + oracleTempSchema <- input$oracleTempSchema + if (oracleTempSchema == "") + oracleTempSchema <- NULL + sql <- withCallingHandlers(suppressWarnings(translateSql(sql, targetDialect = tolower(input$dialect), oracleTempSchema = oracleTempSchema)$sql), warning = handleWarning) + if (!is.null(warningString)) + output$warnings <- warningString + # cache$target <- sql + # cache$clicks <- input$renderTranslate + return(sql) + # } + }) + + output$parameterInputs <- renderUI({ + params <- parameters() + sourceSql <- input$source + + createRow <- function(param, sourceSql) { + # Get current values if already exists: + value <- isolate(input[[param]]) + + if (is.null(value)) { + # Get default values: + value <- regmatches(sourceSql, regexpr(paste0("\\{\\s*DEFAULT\\s*@", param, "\\s=[^}]+}"), sourceSql)) + if (length(value) == 1) { + value = sub(paste0("\\{\\s*DEFAULT\\s*@", param, "\\s=\\s*"), "", sub("\\}$", "", value)) + } else { + value = "" + } + } + textInput(param, param, value = value) + } + lapply(params, createRow, sourceSql = sourceSql) + }) + + observeEvent(input$open, { + sql <- SqlRender::readSql(input$open$datapath) + updateTextAreaInput(session, "source", value = sql) + }) + + output$save <- downloadHandler( + filename = function() { + paste('query-', Sys.Date(), '.sql', sep='') + }, + content = function(con) { + SqlRender::writeSql(sql = input$source, targetFile = con) + } + ) +}) + diff --git a/inst/shinyApps/SqlDeveloper/ui.R b/inst/shinyApps/SqlDeveloper/ui.R new file mode 100644 index 00000000..197e5e7e --- /dev/null +++ b/inst/shinyApps/SqlDeveloper/ui.R @@ -0,0 +1,45 @@ +library(shiny) +library(shinydashboard) +source("widgets.R") + +dashboardPage( + dashboardHeader(title = "SqlRender Developer"), + dashboardSidebar( + sidebarMenu( + menuItemFileInput("open", "Open file"), + menuItemDownloadLink("save", "Save"), + menuItem("Open new tab", href = "", icon = shiny::icon("plus-square")), + menuItemCopyTextAreaToClipboard("source", "Copy source to clipboard"), + menuItemCopyDivToClipboard("target", "Copy target to clipboard") + ) + ), + dashboardBody( + fluidRow( + column(width = 9, + box( + title = "Source: OHDSI SQL", width = NULL, status = "primary", + textAreaInput("source", NULL, width = "100%", height = "300px") + ), + box( + title = "Target: Rendered translation", width = NULL, + # tags$table(width = "100%", + # tags$tr( + # tags$td(align = "left", actionButton("renderTranslate", "Render and translate")), + # tags$td(align = "right", checkboxInput("continuous", "Auto render and translate")))), + pre(textOutput("target")) + ) + ), + column(width = 3, + box(background = "light-blue", + h4("Target dialect"), width = NULL, + selectInput("dialect", NULL, choices = c("BigQuery", "Impala", "Netezza", "Oracle", "PDW", "PostgreSQL", "RedShift", "SQL Server" ), selected = "SQL Server"), + h4("Oracle temp schema"), + textInput("oracleTempSchema", NULL), + h4("Parameters"), + uiOutput("parameterInputs"), + textOutput("warnings") + ) + ) + ) + ) +) diff --git a/inst/shinyApps/SqlDeveloper/widgets.R b/inst/shinyApps/SqlDeveloper/widgets.R new file mode 100644 index 00000000..5b371712 --- /dev/null +++ b/inst/shinyApps/SqlDeveloper/widgets.R @@ -0,0 +1,40 @@ +menuItemFileInput <- function(inputId, text, icon = shiny::icon("file-text-o")) { + script <- "document.getElementById('%id%').click(); return false;" + script <- gsub("%id%", inputId, script) + list(div(fileInput(inputId, ""), style = "display: none;"), + tags$li(class = "treeview", a(href = "#", onclick = script, icon, text))) +} + +menuItemDownloadLink <- function(inputId, label, icon = shiny::icon("floppy-o")) { + tags$li(class = "treeview", + tags$a(id = inputId, + class = "shiny-download-link", + href = "", + target = "_blank", + download = NA, + icon, + label) + ) +} + +menuItemCopyTextAreaToClipboard <- function(textAreaId, label, icon = shiny::icon("clipboard")) { + script <- " + element = $('