build_sql_in: Build a SQL IN statement.

Description Usage Arguments Details Value Examples

Description

Returns SQL IN statement as a string. Supports multi-variable value matching with tuples.

Usage

1
build_sql_in(var_names, values)

Arguments

var_names

A character vector specifying the names of the database columns to which the condition applies. If values is a vector, names should have a length of 1. If values is a data frame, names should have a length of ncol(values).

values

A vector or data frame containing values to match on. Factors will be converted to strings. Rows of a data frame are treated as tuples.

Details

Concatenates values in a vector and returns them in a SQL conditional format. This is necessary since Friday Institute researchers are given read-only access to the database. Otherwise, you could use dplyr join commands with copy=TRUE, which would create a temporary table in the database, so the database can handle the calculations. If this breaks, you can always pull the entire table and do subsetting locally, but that's obviously expensive.

Value

A string of format "name IN (value1, value2, ...)" for vector inputs and "(name1, name2) IN ((name1value1, name2value1), ...)" for data frames.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## Not run: 
courseids <- c(1, 2, 3)
build_sql_in("courseid", courseids)

# tuple
tuple <- tribble(
  ~courseid, ~userid,
  1,         1,
  1,         2,
  2,         3,
  2,         4
)
build_sql_in(c("courseid", "userid"), tuple)

## End(Not run)

TheFridayInstitute/fimoodler documentation built on May 28, 2019, 9:37 a.m.