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

Alias hides right table column in join #13210

Closed
euyuil opened this issue Aug 1, 2020 · 1 comment · Fixed by #62185
Closed

Alias hides right table column in join #13210

euyuil opened this issue Aug 1, 2020 · 1 comment · Fixed by #62185
Labels
bug Confirmed user-visible misbehaviour in official release comp-joins JOINs comp-sql General SQL support st-hold We've paused the work on issue for some reason

Comments

@euyuil
Copy link

euyuil commented Aug 1, 2020

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 TABLE statements 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;

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';
@euyuil euyuil added the bug Confirmed user-visible misbehaviour in official release label Aug 1, 2020
@4ertus2 4ertus2 changed the title 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 Aug 11, 2020
@4ertus2 4ertus2 self-assigned this Aug 11, 2020
@DouMiaoO-Oo
Copy link

I have a similar error in ver 20.6.4.44 without join.

This is my script

select
	'2020-07-15' as dt
from
	recom_stats_dws.load_clk_log_day as tbl
where
	tbl.dt='20200715';

I got error message:

DB::Exception: Unknown identifier: dt there are columns: label (version 20.6.4.44 (official build))

When I rename dt, the script below will run the right way as I expected without error:

select
	'2020-07-15' as rename_dt
from
	recom_stats_dws.load_clk_log_day as tbl
where
	tbl.dt='20200715';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed user-visible misbehaviour in official release comp-joins JOINs comp-sql General SQL support st-hold We've paused the work on issue for some reason
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants