parse_query {queryparser} | R Documentation |
Parse a SQL query
Description
Parses a SQL SELECT
statement into a list with R
expressions
Usage
parse_query(query, tidyverse = FALSE, secure = TRUE)
Arguments
query |
a character string containing a SQL |
tidyverse |
set to |
secure |
set to |
Details
See the
current
limitations section of the README
for information about what types
of queries are supported.
Value
A list object with named elements representing the clauses of the query, containing sublists of unevaluated R expressions translated from the SQL expressions in the query.
Depending on the arguments, the returned list and its sublists will have
attributes named distinct
and aggregate
with logical values
that can aid in the evaluation of the R expressions. If query
contains one or more joins, then the sublist named from
will have
attributes named join_types
and join_conditions
specifying
the types of join and the join conditions.
See Also
Examples
my_query <- "SELECT origin, dest,
COUNT(flight) AS num_flts,
round(AVG(distance)) AS dist,
round(AVG(arr_delay)) AS avg_delay
FROM flights
WHERE distance BETWEEN 200 AND 300
AND air_time IS NOT NULL
GROUP BY origin, dest
HAVING num_flts > 3000
ORDER BY num_flts DESC, avg_delay DESC
LIMIT 100;"
parse_query(my_query)
parse_query(my_query, tidyverse = TRUE)