Skip to content

UNKNOWN_IDENTIFIER instead of NOT_AN_AGGREGATE in a query with INNER JOIN and GROUP BY #50705

Closed

Description

@ruslandoga
SELECT
    count(s0.number),
    s1.half
FROM system.numbers AS s0
INNER JOIN
(
    SELECT
        number,
        number / 2 AS half
    FROM system.numbers
    LIMIT 10
) AS s1 ON s0.number = s1.number
GROUP BY s0.number > 5
LIMIT 10

produces

Received exception from server (version 23.5.1):
Code: 47. DB::Exception: Received from localhost:9000. DB::Exception: Unknown column: half, there are only columns greater(number, 5), count(number). (UNKNOWN_IDENTIFIER)

instead of the expected

Received exception from server (version 23.5.1):
Code 215: <...> Column half is not under aggregate function and not in GROUP BY <...> (NOT_AN_AGGREGATE)

Repro: https://fiddle.clickhouse.com/373d6cd7-160f-41c1-93cb-15e62e5e0d32

Does it reproduce on recent release?

Yes, on 23.5.1

Activity

  1. added
    potential bug
    on Jun 8, 2023
  2. ruslandoga commented on Jun 8, 2023

    @ruslandoga
    ContributorAuthor

    Note that the suggested available columns in the error message are not columns but expressions from select and group by: columns greater(number, 5), count(number)

  3. added
    unexpected behaviour
    and removed
    potential bug
    on Jun 27, 2023
  4. den-crane commented on Jun 27, 2023

    @den-crane
    Contributor

    solved in analyzer

    set allow_experimental_analyzer=1;
    
    SELECT
        count(s0.number),
        s1.half
    FROM system.numbers AS s0
    INNER JOIN
    (
        SELECT
            number,
            number / 2 AS half
        FROM system.numbers
        LIMIT 10
    ) AS s1 ON s0.number = s1.number
    GROUP BY s0.number > 5
    LIMIT 10
    
    DB::Exception: Column s1.half is not under aggregate function and not in GROUP BY keys. 
    (NOT_AN_AGGREGATE)

    https://fiddle.clickhouse.com/7fd3e5a3-1b95-4cb6-a2de-e959c38c61dd

  5. added a commit that references this issue on Apr 10, 2024
  6. ruslandoga commented on Apr 16, 2024

    @ruslandoga
    ContributorAuthor

    @nikitamikhaylov thank you!

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

    unexpected behaviour

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions