Skip to content

Column taken from wrong table in a left join, when column name has special character (dot). #39634

Closed

Description

@eschaubert

In the following code example I try to join two similar tables, and cherry pick the columns that should be selected. Unfortunately, in this case the columns include a . (dot) as part of its name. Clickhouse chooses the wrong table for this column even though its explicitly stated from which table it should be taken. So in the following code i get a 1 instead of the 2. If I use quotes around the column name like in the second code block it works as intended. But in the first case, I would expect to get an error or a warning message at least. Is absolutely counterintuitive, that it would take it from test1 when running this code.

Clickhouse version: 21.10.2.15

CREATE TABLE qa.test1
(
    `pk` String,
    `x.y` Decimal(18, 4)
)
ENGINE = MergeTree()
ORDER BY (pk);

CREATE TABLE qa.test2
(
    `pk` String,
    `x.y` Decimal(18, 4)
)
ENGINE = MergeTree()
ORDER BY (pk);

INSERT INTO qa.test1 SELECT 'pk1', 1;

INSERT INTO qa.test2 SELECT 'pk1', 2;

SELECT t1.pk, t2.x.y 
FROM qa.test1 t1 
LEFT JOIN qa.test2 t2 
	on t1.pk = t2.pk;
SELECT t1.pk, t2.`x.y`
FROM qa.test1 t1 
LEFT JOIN qa.test2 t2 
	on t1.pk = t2.pk;

Activity

  1. added
    potential bug
    on Jul 27, 2022
  2. den-crane commented on Jul 27, 2022

    @den-crane
    Contributor
    SELECT t1.pk,    t2.x.y
    ...
    ┌─pk──┬─x.y─┐
    │ pk1 │   1 │
    └─────┴─────┘
    
    SELECT  t1.pk, t2.`x.y`
    ...
    ┌─pk──┬─t2.x.y─┐
    │ pk1 │      2 │
    └─────┴────────┘
    
  3. added
    comp-joins
    bug
    and removed
    potential bug
    on Jul 27, 2022
  4. den-crane commented on Jul 27, 2022

    @den-crane
    Contributor

    related to "nightmare" #23194

  5. added and removed
    bug
    on Oct 5, 2022
  6. 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

    comp-joins

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions