Skip to content

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

Closed

Description

@siradjev

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.

Activity

  1. added
    potential bug
    on Sep 9, 2021
  2. added
    bug
    minor
    and removed
    potential bug
    on Sep 13, 2021
  3. alexey-milovidov commented on Jan 18, 2022

    @alexey-milovidov
    Member

    Hold until #23194 is implemented.

  4. added a commit that references this issue on Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugminor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions