Partially fix idiotic code in JOINs

This commit is contained in:
Alexey Milovidov 2021-07-03 03:23:14 +03:00
parent 1e9fbdb02c
commit b20c0e2674
3 changed files with 15 additions and 1 deletions

View File

@ -48,7 +48,7 @@ void replaceJoinedTable(const ASTSelectQuery & select_query)
if (table_expr.database_and_table_name)
{
const auto & table_id = table_expr.database_and_table_name->as<ASTTableIdentifier &>();
String expr = "(select * from " + table_id.name() + ") as " + table_id.shortName();
String expr = "(SELECT * FROM " + backQuote(table_id.name()) + ") AS " + backQuote(table_id.shortName());
// FIXME: since the expression "a as b" exposes both "a" and "b" names, which is not equivalent to "(select * from a) as b",
// we can't replace aliased tables.

View File

@ -0,0 +1 @@
0 0 1

View File

@ -0,0 +1,13 @@
DROP TABLE IF EXISTS "/t0";
DROP TABLE IF EXISTS "/t1";
create table "/t0" (a Int64, b Int64) engine = MergeTree() partition by a order by a;
create table "/t1" (a Int64, b Int64) engine = MergeTree() partition by a order by a;
insert into "/t0" values (0, 0);
insert into "/t1" values (0, 1);
select * from "/t0" join "/t1" using a;
DROP TABLE "/t0";
DROP TABLE "/t1";