v.21.6Improvement

Now prefer_column_name_to_alias = 1 Favors Column Names in Group By, Having, and Order By

Now prefer_column_name_to_alias = 1 will also favor column names for group by, having and order by. This fixes #23882. #24022 (Amos Bird).
The setting prefer_column_name_to_alias = 1 now applies to GROUP BY, HAVING, and ORDER BY clauses, favoring original column names over aliases in these clauses.

Why it matters

This feature addresses ambiguity and inconsistencies in query interpretation by ensuring that when prefer_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 setting prefer_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.