Skip to content

GROUP BY using WITH columns alias don't work if we call the column using the column name on SELECT #7520

Closed

Description

@YiuRULE

Describe the bug or unexpected behaviour

If we do a GROUP BY using an alias column on the WITH, it consider the following column as not part of the ORDER BY

How to reproduce
Clickhouse server v19.14.3

CREATE TABLE test (`a` UInt32, `b` UInt32) ENGINE = Memory;

WITH
    a as key
SELECT
    a as k1,
    sum(b) as k2
FROM
    test
GROUP BY
    key
ORDER BY k1, k2;

Code: 215. DB::Exception: Received from 127.0.0.1:10000. DB::Exception: Column a is not under aggregate function and not in GROUP BY.. 

Expected behavior
This query should be executable as the alias key and the column a share the same expression.

Activity

  1. added
    bug
    on Oct 29, 2019
  2. self-assigned this
    on Oct 29, 2019
  3. YiuRULE commented on Oct 30, 2019

    @YiuRULE
    ContributorAuthor

    I saw also a similar strange behavior who could be related to the following issue.

    for the same database definition as the original pull-request, this request return the error DB::Exception: Unknown identifier: a.

    WITH a as key SELECT key as k1 FROM test GROUP BY key;

    However, if we do WITH a as key SELECT key as k1 FROM test; (so without the grouping key), it's working fine

  4. removed their assignment
    on Oct 16, 2020
  5. added
    st-accepted
    on Apr 17, 2021
  6. added a commit that references this issue on Apr 2, 2024
  7. added
    comp-ddl
    on Mar 27, 2026
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

    bugcomp-ddlst-accepted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions