parametrized_query: Parametrize a SQL query

Description Usage Arguments Value Author(s) Examples

View source: R/parametrized_query.R

Description

In a query string put x1x, x2x and so on characters where you want to insert your strings. Provide a list of of strings and those values will be replaced and query will be ready to be sent to database.

Usage

1
parametrized_query(query, params)

Arguments

query

String representing your query with x1x, x2x, ... on places where you want to put your parameters

params

Vector of strings to be placed in a query on places x1x, x2x,.. respectively.

Value

A parametrised query ready to be sent to the database.

Author(s)

Elio Bartoš

Examples

1
2
3
4
5
6
7
8
9
query = "
select date, sum(revenue) as revenue
  from my_sample_table
  where date between 'x1x' and 'x2x'
  group by 1
  order by 1;
"
p_query = parametrized_query(query, c('2018-09-01', as.character(Sys.Date())))
cat(p_query)

eliobartos/misc documentation built on Oct. 8, 2021, 1:10 a.m.