v.21.6Improvement
Now prefer_column_name_to_alias = 1 Favors Column Names in Group By, Having, and Order By
Nowprefer_column_name_to_alias = 1will also favor column names forgroup by,havingandorder by. This fixes #23882. #24022 (Amos Bird).
Why it matters
This feature addresses ambiguity and inconsistencies in query interpretation by ensuring that whenprefer_column_name_to_alias is enabled, ClickHouse uses column names rather than aliases in GROUP BY, HAVING, and ORDER BY. This resolves issues related to alias resolution and improves query predictability and correctness.How to use it
To enable this behavior, set the settingprefer_column_name_to_alias to 1 in your session, query, or configuration. For example:SET prefer_column_name_to_alias = 1;After this, ClickHouse will use the actual column names in
GROUP BY, HAVING, and ORDER BY clauses instead of aliases.