Learn R Programming

queryparser (version 0.3.2)

extract_alias: 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)

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

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.

Examples

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

Run the code above in your browser using DataLab