Skip to content

Condition pushdown: Window function is found in HAVING in query.  #47818

@UnamedRus

Description

@UnamedRus

Describe what's wrong

ClickHouse pushdown condition for Window Function

Does it reproduce on recent release?

Yes, 23.2

LAPTOP-. :) SELECT * FROM (SELECT dense_rank() OVER (ORDER BY number DESC) AS row FROM numbers(10)) WHERE row < 3;

SELECT *
FROM
(
    SELECT dense_rank() OVER (ORDER BY number DESC) AS row
    FROM numbers(10)
)
WHERE row < 3

┌─row─┐
│   1 │
│   2 │
└─────┘

2 rows in set. Elapsed: 0.001 sec.

LAPTOP-. :) SELECT * FROM (WITH dense_rank() OVER (ORDER BY number DESC) AS row SELECT row FROM numbers(10)) WHERE row < 3;

SELECT *
FROM
(
    WITH dense_rank() OVER (ORDER BY number DESC) AS row
    SELECT row
    FROM numbers(10)
)
WHERE row < 3


0 rows in set. Elapsed: 0.001 sec.

Received exception:
Code: 184. DB::Exception: Window function row is found in HAVING in query: While processing dense_rank() OVER (ORDER BY number DESC) AS row. (ILLEGAL_AGGREGATION)

Expected behavior

Query works

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed user-visible misbehaviour in official releaseminorPriority: minor

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions