expression-alias
What it does
Section titled “What it does”Reports a column of a SELECT list that is an expression (a function call, a literal, an operator, a CASE) with no alias. A column, *, a parenthesised expression and a :: cast of a column are left alone; CAST(a AS int) is a function call and is reported.
Why it matters
Section titled “Why it matters”Without an alias the name of the column is chosen by the database (?column?, count, sum, expr1), and it differs between databases and versions. Code that reads the result by name, and views built on the query, then depend on a generated name.
To fix, add AS name.
Example
Section titled “Example”select 1, sum(a), a + 1, b, t.*, a::int, (a), a & b, case when a then 1 end, count(*) as n from t;Configuration
Section titled “Configuration”sql: lint: rules: expression-alias: warn # off (default), warn, errorEnabled by the presets: sql/sqlfluff.
Suppress one line with sudsy-disable-next-line expression-alias in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| sqlfluff | AL03 |
full |