extract_alias {queryparser}R Documentation

Extract the column alias from a SQL expression

Description

Extracts the column alias assignment from an expression used in the SELECT list of a SQL query

Usage

extract_alias(expr)

Arguments

expr

a character string containing a SQL expression which might have a column alias assignment at the end

Details

The expression must not contain any unquoted whitespace characters except spaces, and there must be no unquoted runs or two or more spaces. Use squish_sql to satisfy this whitespace requirement.

queryparser also uses this function internally to extract table aliases used in the FROM clause.

Value

a character string containing the inputted SQL expression with the column alias assignment removed (if it existed) and with the assigned alias as its name

Examples

expr <- "round(AVG(arr_delay)) AS avg_delay"
extract_alias(expr)

[Package queryparser version 0.3.2 Index]