Description Usage Arguments Details Value See Also Examples
View source: R/sqlparse_retic.R
Parse one or several SQL statements (non-validating).
1 |
sql |
Character string containing one or more SQL statements to be formatted. |
encoding |
Character string specifying the input encoding. Default: |
This function is a wrapper to the sqlparse.parse() function from the sqlparse Python module, which is a non-validating SQL parser.
List with reference class objects which are converted instances of the custom Python class Statement. These tree-ish representations of the parsed statements can be analyzed with a set of reference class methods (accessed via $). See the documentation of the corresponding Python methods: https://sqlparse.readthedocs.io/en/stable/analyzing/.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | if (reticulate::py_module_available("sqlparse")) {
library("sqlparseR")
raw <- "select*from foo; select*from bar;"
parsed <- sql_parse(raw)
## Analyzing the parsed statements
# e.g., get name of identifier in second statement
n <- parsed[[2]]$get_name()
print(n)
# e.g., get a (Python) generator yielding ungrouped tokens of the first statement
token_it <- parsed[[1]]$flatten()
for (t in reticulate::iterate(token_it)) {
print(t)
}
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.