unqualify_query: Remove prefixes from column references in a parsed SQL query

View source: R/unqualify.R

unqualify_queryR Documentation

Remove prefixes from column references in a parsed SQL query

Description

Unqualifies column references in the clauses of a parsed SQL SELECT statement that begin with any of the specified prefixes followed by a dot

Usage

unqualify_query(tree, prefixes, except = character(0))

Arguments

tree

a list returned by parse_query containing named elements representing the clauses of a SQL SELECT statement

prefixes

a character vector containing one or more table names or table aliases

except

a character vector containing column references to leave as is (optional)

Details

In the returned list, the FROM clause is unmodified and column alias assignments made in the SELECT clause are unmodified.

Value

A list the same as tree but with all column references in the SELECT, WHERE, GROUP BY, HAVING, and ORDER BY clauses unqualified, except those in except

See Also

parse_query

Examples

my_query <- "SELECT f.flight,
    manufacturer, p.model
  FROM flights f
    JOIN planes p USING (tailnum);"

unqualify_query(
  parse_query(my_query),
  prefixes = c("p", "f")
)

queryparser documentation built on Jan. 10, 2023, 1:08 a.m.