From a89e3df40a42514e3eea183eb7e121fa12ab28e8 Mon Sep 17 00:00:00 2001 From: Amos Bird Date: Tue, 6 Apr 2021 21:08:29 +0800 Subject: [PATCH] Disable table function view in expression (#21465) --- src/Parsers/ASTFunction.cpp | 8 ++++++++ .../queries/0_stateless/01715_table_function_view_fix.sql | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/Parsers/ASTFunction.cpp b/src/Parsers/ASTFunction.cpp index 3cb2e8bfa37..95d668dc8b6 100644 --- a/src/Parsers/ASTFunction.cpp +++ b/src/Parsers/ASTFunction.cpp @@ -15,8 +15,16 @@ namespace DB { +namespace ErrorCodes +{ + extern const int UNEXPECTED_EXPRESSION; +} + void ASTFunction::appendColumnNameImpl(WriteBuffer & ostr) const { + if (name == "view") + throw Exception("Table function view cannot be used as an expression", ErrorCodes::UNEXPECTED_EXPRESSION); + writeString(name, ostr); if (parameters) diff --git a/tests/queries/0_stateless/01715_table_function_view_fix.sql b/tests/queries/0_stateless/01715_table_function_view_fix.sql index de5150b7b70..b96609391b5 100644 --- a/tests/queries/0_stateless/01715_table_function_view_fix.sql +++ b/tests/queries/0_stateless/01715_table_function_view_fix.sql @@ -1 +1,3 @@ SELECT view(SELECT 1); -- { clientError 62 } + +SELECT sumIf(dummy, dummy) FROM remote('127.0.0.{1,2}', numbers(2, 100), view(SELECT CAST(NULL, 'Nullable(UInt8)') AS dummy FROM system.one)); -- { serverError 183 }