Skip to content

Unknown identifier with alias substitution  #23053

Closed

Description

@UnamedRus

How to reproduce
Clickhouse version 21.5

CREATE TABLE repl_tbl
(
    `key` UInt32,
    `val_1` UInt32,
    `val_2` String,
    `val_3` String,
    `val_4` String,
    `val_5` UUID,
    `ts` DateTime
)
ENGINE = ReplacingMergeTree(ts)
ORDER BY key

set prefer_column_name_to_alias=1;

WITH 10 as k SELECT k as key, * FROM repl_tbl WHERE key = k;
 
Received exception from server (version 21.5.1):
Code: 47. DB::Exception: Received from localhost:9000. DB::Exception: Unknown identifier: key there are columns: val_1, val_2, val_3, val_4, val_5, ts: While processing key = (10 AS k).

Activity

  1. alexey-milovidov commented on Oct 19, 2022

    @alexey-milovidov
    Member
  2. UnamedRus commented on Mar 27, 2023

    @UnamedRus
    ContributorAuthor

    23.2

    INSERT INTO repl_tbl (key) SELECT number
    FROM numbers(10)
    
    Query id: 44f1fa6d-3d52-4d37-ae54-e58e02eae038
    
    Ok.
    
    0 rows in set. Elapsed: 0.003 sec.
    
    LAPTOP-. :) WITH 10 as k SELECT k as key, * FROM repl_tbl WHERE key = k;
    
    WITH 10 AS k
    SELECT
        k AS key,
        *
    FROM repl_tbl
    WHERE key = k
    SETTINGS allow_experimental_analyzer = 0
    
    Query id: b3e7ad59-1a68-4e44-8027-5cb1ddedf8b2
    
    ┌─key─┬─key─┬─val_1─┬─val_2─┬─val_3─┬─val_4─┬─val_5────────────────────────────────┬──────────────────ts─┐
    │  10 │  10 │     0 │       │       │       │ 00000000-0000-0000-0000-000000000000 │ 1970-01-01 00:00:00 │
    │  10 │  10 │     0 │       │       │       │ 00000000-0000-0000-0000-000000000000 │ 1970-01-01 00:00:00 │
    │  10 │  10 │     0 │       │       │       │ 00000000-0000-0000-0000-000000000000 │ 1970-01-01 00:00:00 │
    │  10 │  10 │     0 │       │       │       │ 00000000-0000-0000-0000-000000000000 │ 1970-01-01 00:00:00 │
    │  10 │  10 │     0 │       │       │       │ 00000000-0000-0000-0000-000000000000 │ 1970-01-01 00:00:00 │
    │  10 │  10 │     0 │       │       │       │ 00000000-0000-0000-0000-000000000000 │ 1970-01-01 00:00:00 │
    │  10 │  10 │     0 │       │       │       │ 00000000-0000-0000-0000-000000000000 │ 1970-01-01 00:00:00 │
    │  10 │  10 │     0 │       │       │       │ 00000000-0000-0000-0000-000000000000 │ 1970-01-01 00:00:00 │
    │  10 │  10 │     0 │       │       │       │ 00000000-0000-0000-0000-000000000000 │ 1970-01-01 00:00:00 │
    │  10 │  10 │     0 │       │       │       │ 00000000-0000-0000-0000-000000000000 │ 1970-01-01 00:00:00 │
    └─────┴─────┴───────┴───────┴───────┴───────┴──────────────────────────────────────┴─────────────────────┘
    
    WITH 10 AS k
    SELECT
        k AS key,
        *
    FROM repl_tbl
    WHERE key = k
    SETTINGS allow_experimental_analyzer = 1
    
    Query id: fbe3af33-65df-4ad5-a5ff-61346b22a54c
    
    ┌─key─┬─repl_tbl.key─┬─val_1─┬─val_2─┬─val_3─┬─val_4─┬─val_5────────────────────────────────┬──────────────────ts─┐
    │  10 │            0 │     0 │       │       │       │ 00000000-0000-0000-0000-000000000000 │ 1970-01-01 00:00:00 │
    │  10 │            1 │     0 │       │       │       │ 00000000-0000-0000-0000-000000000000 │ 1970-01-01 00:00:00 │
    │  10 │            2 │     0 │       │       │       │ 00000000-0000-0000-0000-000000000000 │ 1970-01-01 00:00:00 │
    │  10 │            3 │     0 │       │       │       │ 00000000-0000-0000-0000-000000000000 │ 1970-01-01 00:00:00 │
    │  10 │            4 │     0 │       │       │       │ 00000000-0000-0000-0000-000000000000 │ 1970-01-01 00:00:00 │
    │  10 │            5 │     0 │       │       │       │ 00000000-0000-0000-0000-000000000000 │ 1970-01-01 00:00:00 │
    │  10 │            6 │     0 │       │       │       │ 00000000-0000-0000-0000-000000000000 │ 1970-01-01 00:00:00 │
    │  10 │            7 │     0 │       │       │       │ 00000000-0000-0000-0000-000000000000 │ 1970-01-01 00:00:00 │
    │  10 │            8 │     0 │       │       │       │ 00000000-0000-0000-0000-000000000000 │ 1970-01-01 00:00:00 │
    │  10 │            9 │     0 │       │       │       │ 00000000-0000-0000-0000-000000000000 │ 1970-01-01 00:00:00 │
    └─────┴──────────────┴───────┴───────┴───────┴───────┴──────────────────────────────────────┴─────────────────────┘
    
  3. alexey-milovidov commented on Mar 28, 2023

    @alexey-milovidov
    Member

    @UnamedRus, you forgot to add a test. Every fixed issue should be proven with a test. I will add it.

  4. alexey-milovidov commented on Mar 28, 2023

    @alexey-milovidov
    Member

    Not fixed:

    clickhouse-client --echo -n < 02702_alias_unknown_identifier.sql 
    CREATE TEMPORARY TABLE repl_tbl
    (
        `key` UInt32,
        `val_1` UInt32,
        `val_2` String,
        `val_3` String,
        `val_4` String,
        `val_5` UUID,
        `ts` DateTime
    )
    ENGINE = ReplacingMergeTree(ts)
    ORDER BY `key`;
    set prefer_column_name_to_alias = 1;
    INSERT INTO repl_tbl (key) SELECT number FROM numbers(10);
    WITH 10 as k SELECT k as key, * FROM repl_tbl WHERE key = k;
    
    Received exception from server (version 23.3.1):
    Code: 47. DB::Exception: Received from localhost:9000. DB::Exception: Unknown identifier: key; there are columns: val_1, val_2, val_3, val_4, val_5, ts: While processing key = (10 AS k). (UNKNOWN_IDENTIFIER)
    (query: WITH 10 as k SELECT k as key, * FROM repl_tbl WHERE key = k;)
    
  5. added a commit that references this issue on Apr 2, 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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions