build_query: Build a Simple SQL Query

Description Usage Arguments See Also Examples

View source: R/build.R

Description

Build a Simple SQL Query

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
build_query(
  fields = "*",
  distinct = FALSE,
  schema,
  table,
  where_in_field,
  where_in_vector,
  where_not_in_field,
  where_not_in_vector,
  where_is_null_field,
  where_is_not_null_field,
  case_insensitive = TRUE,
  limit,
  random
)

Arguments

fields

Fields selected for. Defaults to "*".

distinct

If TRUE, the distinct row count will be returned.

schema

The target schema for the operation.

table

Target table for the operation.

where_in_field

Paired with where_in_vector, adds a "WHERE field IN (vector)" clause to the query corresponding to the field-value pair.

where_not_in_field

Paired with where_not_in_vector, adds a "WHERE field NOT IN (vector)" clause to the query corresponding to the field-value pair.

case_insensitive

If TRUE, both sides of the query are converted to lowercase.

limit

(Optional) Integer of the row limit. Takes precedence over random if both arguments are provided.

random

(Optional) Integer of the random number of rows to return. Is preceded by limit if both limit and random are provided.

See Also

render

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Building SQL Statements using R
library(pg13)

# Build a Simple Query
build_query(schema = "public",
            table = "concept_synonym")

build_query(distinct = TRUE,
            schema = "public",
            table = "concept_synonym")


build_query(fields = c("concept_id", "concept_name"),
            distinct = TRUE,
            schema = "public",
            table = "concept_synonym")

# WHERE filters may be applied, but will be ignored if the field-value pair is not provided
build_query(fields = c("concept_id", "concept_name"),
            schema = "public",
            table = "concept_synonym",
            where_in_field = "concept_synonym")

# The query defaults to transforming elements to lowercase for case insensitivity that can be turned off
build_query(fields = c("concept_id", "concept_name"),
            schema = "public",
            table = "concept_synonym",
            where_in_field = "concept_synonym",
            where_in_vector = c("Myocardial Infarction", "Heart Attack"))

build_query(fields = c("concept_id", "concept_name"),
            schema = "public",
            table = "concept_synonym",
            where_in_field = "concept_synonym",
            where_in_vector = c("Myocardial Infarction", "Heart Attack"),
            case_insensitive = FALSE)

patelm9/pg13 documentation built on Dec. 26, 2021, 8:17 p.m.