Skip to content

ClickHouse returns AMBIGUOUS_COLUMN_NAME error #48308

Closed

Description

@ywangtht
CREATE TABLE test
(
    `time` DateTime
)
ENGINE = MergeTree
ORDER BY time
SELECT *
FROM
(
    SELECT
        toUInt64(time) AS time,
        toHour(test.time)
    FROM test
)
ORDER BY time ASC

Query id: b195d950-1ccb-4895-9562-b04341889128


0 rows in set. Elapsed: 0.005 sec.

Received exception from server (version 22.6.1):
Code: 352. DB::Exception: Received from localhost:9000. DB::Exception: Block structure mismatch in (columns with identical name must have identical structure) stream: different types:
time DateTime UInt32(size = 0)
time UInt64 UInt64(size = 0). (AMBIGUOUS_COLUMN_NAME)

It does not work with "WITH" either:

WITH subquery AS (
    SELECT
        toUInt64(time) AS time,
        toHour(test.time)
    FROM test
)
SELECT *
FROM subquery
ORDER BY subquery.time ASC

It starts working if I add one more order by:

SELECT *
FROM
(
    SELECT
        toUInt64(time) AS time,
        toHour(test.time) AS hour
    FROM test
)
ORDER BY time ASC, hour

Activity

  1. added
    unexpected behaviour
    on Mar 31, 2023
  2. den-crane commented on Apr 1, 2023

    @den-crane
    Contributor

    works with analyzer

    SELECT *
    FROM
    (
        SELECT
            toUInt64(time) AS time,
            toHour(test.time)
        FROM test
    )
    ORDER BY time ASC
    SETTINGS allow_experimental_analyzer = 1
    
    Query id: c403e73f-810e-4418-9218-6e403b4fb0c9
    
    Ok.
    
  3. 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

    unexpected behaviour

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions