Skip to content

Cannot create VIEW with aliases on JOIN, get "Cannot detect left and right JOIN keys. JOIN ON section is ambiguous.." #11000

Closed

Description

@vladimir-golovchenko

Normal VIEW is failed when defined JOIN with aliases (taken from stackoverflow).

CREATE TABLE test_table_01 (
    column Int32
) ENGINE = Memory();

CREATE TABLE test_table_02 (
    column Int32
) ENGINE = Memory();

Creating view leads to error:

CREATE VIEW test_view_01 AS
SELECT 
    t1.column,
    t2.column
FROM test_table_01 AS t1 
    INNER JOIN test_table_02 AS t2 ON t1.column = t2.column;
Received exception from server (version 20.3.8):
Code: 352. DB::Exception: Received from localhost:9000. DB::Exception: Cannot detect left and right JOIN keys. JOIN ON section is ambiguous.. Stack trace:

0. Poco::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int) @ 0x10542450 in /usr/bin/clickhouse
1. DB::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int) @ 0x8f4272d in /usr/bin/clickhouse
2. ? @ 0xd50f7e8 in /usr/bin/clickhouse
3. DB::CollectJoinOnKeysMatcher::visit(DB::ASTFunction const&, std::__1::shared_ptr<DB::IAST> const&, DB::CollectJoinOnKeysMatcher::Data&) @ 0xd50f193 in /usr/bin/clickhouse
4. DB::InDepthNodeVisitor<DB::CollectJoinOnKeysMatcher, true, std::__1::shared_ptr<DB::IAST> const>::visit(std::__1::shared_ptr<DB::IAST> const&) @ 0xd4fe16d in /usr/bin/clickhouse
5. DB::SyntaxAnalyzer::analyzeSelect(std::__1::shared_ptr<DB::IAST>&, DB::SyntaxAnalyzerResult&&, DB::SelectQueryOptions const&, std::__1::vector<DB::TableWithColumnNamesAndTypes, std::__1::allocator<DB::TableWithColumnNamesAndTypes> > const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) const @ 0xd4f5538 in /usr/bin/clickhouse
6. ? @ 0xd148295 in /usr/bin/clickhouse
7. DB::InterpreterSelectQuery::InterpreterSelectQuery(std::__1::shared_ptr<DB::IAST> const&, DB::Context const&, std::__1::shared_ptr<DB::IBlockInputStream> const&, std::__1::optional<DB::Pipe>, std::__1::shared_ptr<DB::IStorage> const&, DB::SelectQueryOptions const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) @ 0xd1495ce in /usr/bin/clickhouse
8. DB::InterpreterSelectQuery::InterpreterSelectQuery(std::__1::shared_ptr<DB::IAST> const&, DB::Context const&, DB::SelectQueryOptions const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) @ 0xd14ab89 in /usr/bin/clickhouse
9. DB::InterpreterSelectWithUnionQuery::InterpreterSelectWithUnionQuery(std::__1::shared_ptr<DB::IAST> const&, DB::Context const&, DB::SelectQueryOptions const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) @ 0xd34fcd6 in /usr/bin/clickhouse
10. DB::InterpreterSelectWithUnionQuery::getSampleBlock(std::__1::shared_ptr<DB::IAST> const&, DB::Context const&) @ 0xd3507ba in /usr/bin/clickhouse
11. DB::InterpreterCreateQuery::setProperties(DB::ASTCreateQuery&) const @ 0xd051f62 in /usr/bin/clickhouse
12. DB::InterpreterCreateQuery::createTable(DB::ASTCreateQuery&) @ 0xd05261d in /usr/bin/clickhouse
13. DB::InterpreterCreateQuery::execute() @ 0xd054931 in /usr/bin/clickhouse
14. ? @ 0xd55f038 in /usr/bin/clickhouse
15. DB::executeQuery(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, DB::Context&, bool, DB::QueryProcessingStage::Enum, bool, bool) @ 0xd561c71 in /usr/bin/clickhouse
16. DB::TCPHandler::runImpl() @ 0x9025489 in /usr/bin/clickhouse
17. DB::TCPHandler::run() @ 0x9026470 in /usr/bin/clickhouse
18. Poco::Net::TCPServerConnection::start() @ 0xe3b9a4b in /usr/bin/clickhouse
19. Poco::Net::TCPServerDispatcher::run() @ 0xe3b9ecd in /usr/bin/clickhouse
20. Poco::PooledThread::run() @ 0x105d05b7 in /usr/bin/clickhouse
21. Poco::ThreadImpl::runnableEntry(void*) @ 0x105cc3bc in /usr/bin/clickhouse
22. ? @ 0x105cdd5d in /usr/bin/clickhouse
23. start_thread @ 0x76db in /lib/x86_64-linux-gnu/libpthread-2.27.so
24. __clone @ 0x12188f in /lib/x86_64-linux-gnu/libc-2.27.so

Activity

  1. added
    bug
    on May 18, 2020
  2. added
    comp-joins
    comp-view
    on May 18, 2020
  3. self-assigned this
    on May 18, 2020
  4. den-crane commented on May 18, 2020

    @den-crane
    Contributor

    duplicate #10894

  5. alexey-milovidov commented on Jul 10, 2020

    @alexey-milovidov
    Member

    @4ertus2 This is still relevant.

  6. removed their assignment
    on Oct 16, 2020
  7. pprogs commented on Nov 12, 2020

    @pprogs

    But it somehow works if you put full table names
    this doesnt work

    from customer as cust
            left any join customer_details_v as det
                on cust.CustomerID = det.CustomerID;

    this works

    from test.customer as cust
            left any join test.customer_details_v as det
                on cust.CustomerID = det.CustomerID;
  8. added a commit that references this issue on Apr 10, 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

    bugcomp-joinscomp-viewduplicate

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions