Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown identifier in aggregate function error when using same alias in different levels of query #28777

Closed
siradjev opened this issue Sep 9, 2021 · 1 comment · Fixed by #62185
Labels
bug Confirmed user-visible misbehaviour in official release comp-query-syntax Relates to query parse / aliases resolution etc. minor Priority: minor st-hold We've paused the work on issue for some reason

Comments

@siradjev
Copy link

siradjev commented Sep 9, 2021

When same alias names are used in different levels of query in some cases "unknown identifier" errors are received.

Does it reproduce on recent release?
Yes, reproduces on all builds 21.3, 21.8, latest 21.9 too.

How to reproduce

chserver :) SELECT
:-]     sum(q0.a2) AS a1,
:-]     sum(q0.a1) AS a9
:-] FROM
:-] (
:-]     SELECT
:-]         1 AS a1,
:-]         2 AS a2
:-] ) AS q0
:-] ;

SELECT
    sum(q0.a2) AS a1,
    sum(q0.a1) AS a9
FROM
(
    SELECT
        1 AS a1,
        2 AS a2
) AS q0

Query id: cd2ff574-fcb3-4027-8fee-7a105bccde53


Received exception from server (version 21.8.5):
Code: 47. DB::Exception: Received from chserver:9000. DB::Exception: Unknown identifier 'a1' in aggregate function 'sum(a1) AS a9'.

0 rows in set. Elapsed: 0.121 sec.

chserver :) SELECT
:-]     (q0.a2) AS a1,
:-]     (q0.a1) AS a9
:-] FROM
:-] (
:-]     SELECT
:-]         1 AS a1,
:-]         2 AS a2
:-] ) AS q0
:-] ;

SELECT
    q0.a2 AS a1,
    q0.a1 AS a9
FROM
(
    SELECT
        1 AS a1,
        2 AS a2
) AS q0

Query id: ec6a030a-d8e2-4ad1-b7de-35bb74831ba6

┌─a1─┬─a9─┐
│  2 │  1 │
└────┴────┘

1 rows in set. Elapsed: 0.121 sec.

chserver :)

Expected behavior
It should work disregarding of order of columns in query.

@siradjev siradjev added the potential bug To be reviewed by developers and confirmed/rejected. label Sep 9, 2021
@alesapin alesapin added comp-query-syntax Relates to query parse / aliases resolution etc. bug Confirmed user-visible misbehaviour in official release minor Priority: minor and removed potential bug To be reviewed by developers and confirmed/rejected. labels Sep 13, 2021
@alexey-milovidov alexey-milovidov added the st-hold We've paused the work on issue for some reason label Jan 18, 2022
@alexey-milovidov
Copy link
Member

Hold until #23194 is implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed user-visible misbehaviour in official release comp-query-syntax Relates to query parse / aliases resolution etc. minor Priority: minor st-hold We've paused the work on issue for some reason
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants