Skip to content

expression-alias

SQLstyleno fixdefault: offsql/sqlfluff

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.

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.

Reported
select 1, sum(a), a + 1, b, t.*, a::int, (a), a & b, case when a then 1 end, count(*) as n from t;
sql:
lint:
rules:
expression-alias: warn # off (default), warn, error

Enabled by the presets: sql/sqlfluff.

Suppress one line with sudsy-disable-next-line expression-alias in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
sqlfluff AL03 full