extract_alias: Extract the column alias from a SQL expression

View source: R/extract_alias.R

extract_aliasR 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)

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