diff --git a/tests/queries/0_stateless/02212_cte_and_table_alias.reference b/tests/queries/0_stateless/02212_cte_and_table_alias.reference new file mode 100644 index 00000000000..1d3d2cc6415 --- /dev/null +++ b/tests/queries/0_stateless/02212_cte_and_table_alias.reference @@ -0,0 +1,4 @@ +5000 +5000 +5000 +5000 diff --git a/tests/queries/0_stateless/02212_cte_and_table_alias.sql b/tests/queries/0_stateless/02212_cte_and_table_alias.sql new file mode 100644 index 00000000000..ce0fba4bf56 --- /dev/null +++ b/tests/queries/0_stateless/02212_cte_and_table_alias.sql @@ -0,0 +1,41 @@ +-- https://github.com/ClickHouse/ClickHouse/issues/19222 +SET enable_global_with_statement = 1; + +WITH t AS + ( + SELECT number AS n + FROM numbers(10000) + ) +SELECT count(*) +FROM t AS a +WHERE a.n < 5000; + +WITH t AS + ( + SELECT number AS n + FROM numbers(10000) + ) +SELECT count(*) +FROM t AS a +WHERE t.n < 5000; + + +SET enable_global_with_statement = 0; + +WITH t AS + ( + SELECT number AS n + FROM numbers(10000) + ) +SELECT count(*) +FROM t AS a +WHERE a.n < 5000; + +WITH t AS + ( + SELECT number AS n + FROM numbers(10000) + ) +SELECT count(*) +FROM t AS a +WHERE t.n < 5000;