Description Usage Arguments Note Examples
The query()
function sends a query with dynamic inputs to a PostgreSQL database, allowing loops and automated reporting.
The madlib()
function just prints the query to console after replacing dynamic inputs, useful for debugging.
1 2 3 |
query |
A character string with dynamic inputs surrounded by "%" (i.e. |
... |
A named series of objects to insert into the query, these CAN be reused. Objects of length 1 will be left as is, whereas objects of length > 1 will be surrounded with brackets. Objects of type character will be surrounded by single quotations and objects of type numeric will be left as is. |
Ensure there is a connection obejct 'conn' in your environment;
Do not comment with --comment
, instead use /*comment*/
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | query(query = "select * from table where place in %places% and year in %years%;",
places = c('NYC', 'Vancouver', 'Hamilton'),
years = c(2019, 2018, 2017))
query <- "
select *
from table
where place in %places%
and year in %years%
;
"
places <- c('NYC', 'Vancouver', 'Hamilton')
years <- c(2019, 2018, 2017)
query(query = query,
places = places,
years = years)
madlib(query = "select * from table where place in %places% and year in %years%;",
places = c('NYC', 'Vancouver', 'Hamilton'),
years = c(2019, 2018, 2017)) # returns a character object
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.