v.20.10New Feature

Introduce enable_global_with_statement to Propagate WITH Statements in Select Queries

Introduce enable_global_with_statement setting which propagates the first select's WITH statements to other select queries at the same level, and makes aliases in WITH statements visible to subqueries. #15451 (Amos Bird).
Introduces the enable_global_with_statement setting that propagates the first SELECT statement's WITH aliases to other SELECT queries at the same level and makes those aliases visible inside subqueries.

Why it matters

This feature addresses the limitation where WITH expressions and their aliases are scoped only to the individual SELECT statement they are defined in. By enabling this setting, users can define common aliases once and have them automatically available across multiple queries at the same nesting level and within subqueries, improving query readability and reducing redundancy.

How to use it

To use this feature, set the configuration option enable_global_with_statement to 1 or true in your ClickHouse session or configuration file. This will activate global propagation of WITH aliases for queries executed within the session.