v.25.5Improvement

Fix the inconsistent

Fix the inconsistent formatting of certain queries with the EXCEPT operator. If the left-hand side of the EXCEPT operator ends with *, the formatted query loses parentheses and is then parsed as a * with the EXCEPT modifier. These queries are found by the fuzzer and are unlikely to be found in practice. This closes #79950. #79952 (Alexey Milovidov).
Fixes the inconsistent formatting of queries using the EXCEPT operator where the left-hand side ends with *, preventing incorrect parsing issues caused by missing parentheses.

Why it matters

This change addresses a rare parsing problem discovered by fuzz testing where the query formatter would remove necessary parentheses around the left-hand side expression ending with before the EXCEPT operator. Without the parentheses, the query is misinterpreted as a with an EXCEPT modifier, potentially causing errors. The fix ensures that formatted queries maintain correct syntax and parsing reliability.

How to use it

This fix is applied automatically in the ClickHouse query formatter when formatting queries containing the EXCEPT operator and left-hand side expressions ending with *. Users do not need to enable or configure anything manually.