Repository navigation
Description
Describe the bug
Failure happens when selecting a constant renaming to the same name with an existing column of a joined table which is also in where clause.
How to reproduce
-
Which ClickHouse server version to use: version 20.3.12.112 (official build)
-
Which interface to use, if matters: No matter.
-
Non-default settings, if any: Not any.
-
CREATE TABLEstatements for all tables involved
CREATE TABLE test_a_table (
name String,
a_col String
)
Engine = MergeTree()
ORDER BY name;
CREATE TABLE test_b_table (
name String,
b_col String,
some_val String
)
Engine = MergeTree()
ORDER BY name;
- Sample data for all these tables, use clickhouse-obfuscator if necessary
No data is needed to reproduce the error.
- Queries to run that lead to unexpected result
SELECT
b.name name,
a.a_col a_col,
b.b_col b_col,
'N' some_val
from test_a_table a
join test_b_table b on a.name = b.name
where b.some_val = 'Y';
Expected behavior
A clear and concise description of what you expected to happen.
The query is expected to be successful.
Error message and/or stacktrace
If applicable, add screenshots to help explain your problem.
Code: 47, e.displayText() = DB::Exception: Unknown identifier: some_val there are columns: name, a_col, b.name, b_col (version 20.3.12.112 (official build))
Additional context
Add any other context about the problem here.
These queries are successful:
SELECT
b.name name,
a.a_col a_col,
b.b_col b_col -- some_val not selected
from test_a_table a
join test_b_table b on a.name = b.name
where b.some_val = 'Y';
SELECT
b.name name,
a.a_col a_col,
b.b_col b_col,
b.some_val some_val -- use b.some_val instead of a constant
from test_a_table a
join test_b_table b on a.name = b.name
where b.some_val = 'Y';
SELECT
b.name name,
a.a_col a_col,
b.b_col b_col,
'N' some_val2 -- do not rename to some_val
from test_a_table a
join test_b_table b on a.name = b.name
where b.some_val = 'Y';
SELECT
b.name name,
a.a_col a_col,
b.b_col b_col,
'N' some_val
from test_a_table a
join test_b_table b on a.name = b.name; -- no where clause
SELECT
b.name name,
a.a_col a_col,
b.b_col b_col,
if(b.some_val='','N','N') some_val -- an interesting workaround...
from test_a_table a
join test_b_table b on a.name = b.name
where b.some_val = 'Y';
However, this won't work either:
SELECT
b.name name,
a.a_col a_col,
b.b_col b_col,
if(1,'N',b.some_val) some_val -- b.some_val is not actually evaluated
from test_a_table a
join test_b_table b on a.name = b.name
where b.some_val = 'Y';
Activity
[-]Code: 47, e.displayText() = DB::Exception: Unknown identifier: XXX there are columns: A, B, ... (version 20.3.12.112 (official build))[/-][+]Alias hides right table column in join[/+]DouMiaoO-Oo commentedon Aug 25, 2020
I have a similar error in ver 20.6.4.44 without join.
This is my script
I got error message:
When I rename
dt, the script below will run the right way as I expected without error:Close: #13210