Skip to content

Analyzer: Expression can not be resolved from parent scope #71659

@nikitamikhaylov

Description

@nikitamikhaylov

Company or project name

ClickHouse inc.

Describe what's wrong

Identifiers from the nested CTE are not evaluated properly.

https://fiddle.clickhouse.com/a62f1ed0-aa44-44af-888a-5b194d81b5a6

Does it reproduce on the most recent release?

Yes.

How to reproduce

CREATE TABLE test
(
    a UInt64,
    b UInt64,
)
ENGINE = MergeTree
ORDER BY tuple();

SET allow_experimental_analyzer=1;

WITH
   (a > b) as cte,
   query AS
    (
        SELECT count()
        FROM test
        WHERE cte
    )
SELECT *
FROM query;

Error message and/or stacktrace

Received exception from server (version 24.10.1):
Code: 47. DB::Exception: Received from localhost:9000. DB::Exception: Unknown expression or function identifier `a` in scope WITH a > b AS cte, query AS (SELECT count() FROM test WHERE cte) SELECT * FROM query. (UNKNOWN_IDENTIFIER)
(query: WITH
   (a > b) as cte,
   query AS
    (
        SELECT count()
        FROM test
        WHERE cte
    )
SELECT *
FROM query;)

Metadata

Metadata

Assignees

Labels

analyzerIssues and pull-requests related to new analyzerbugConfirmed user-visible misbehaviour in official release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions