Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AMBIGUOUS_IDENTIFIER when join table on itself and left table has no alias #45389

Open
qoega opened this issue Jan 18, 2023 · 0 comments
Open

Comments

@qoega
Copy link
Member

qoega commented Jan 18, 2023

CREATE TABLE IF NOT EXISTS t0
(
    `id` INT UNSIGNED NOT NULL,
    `rev` INT UNSIGNED NOT NULL,
    `content` varchar(200) NOT NULL
)
ENGINE = MergeTree
PRIMARY KEY (id, rev)

CREATE TABLE IF NOT EXISTS t1
(
    `id` INT UNSIGNED NOT NULL,
    `rev` INT UNSIGNED NOT NULL,
    `content` varchar(200) NOT NULL
)
ENGINE = MergeTree
PRIMARY KEY (id, rev)

SELECT SUM(t1.rev) AS aggr
FROM t1
INNER JOIN t0 AS right_0 ON t1.id = right_0.id
INNER JOIN t1 AS right_1 ON t1.id = right_1.id

Query id: 638e23fa-f416-4207-9280-9e0dff15448c


0 rows in set. Elapsed: 0.014 sec.

Received exception from server (version 22.13.1):
Code: 207. DB::Exception: Received from localhost:9000. DB::Exception: JOIN  database3TLPAggregate.t1 ALL INNER JOIN database3TLPAggregate.t0 AS right_0 ON id = id ALL INNER JOIN database3TLPAggregate.t1 AS right_1 ON t1.id = right_1.id ambiguous identifier 't1.id'. In scope SELECT SUM(t1.rev) AS aggr FROM t1 INNER JOIN t0 AS right_0 ON t1.id = right_0.id INNER JOIN t1 AS right_1 ON t1.id = right_1.id. (AMBIGUOUS_IDENTIFIER)

MySQL resolves aliases correctly
http://sqlfiddle.com/#!9/0acdc0/2

Postgres also does not complain:
http://sqlfiddle.com/#!17/daee03/1

@kitaisreal can we resolve this types or ambuguity?
I even thought that we can have a setting that defines how we scope aliases - as in SQL standard or ClickHouse way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants