diff --git a/src/Common/ErrorCodes.cpp b/src/Common/ErrorCodes.cpp index ad0463db889..b6523d772f2 100644 --- a/src/Common/ErrorCodes.cpp +++ b/src/Common/ErrorCodes.cpp @@ -549,6 +549,7 @@ M(579, INCORRECT_PART_TYPE) \ M(580, CANNOT_SET_ROUNDING_MODE) \ M(581, TOO_LARGE_DISTRIBUTED_DEPTH) \ + M(582, FUNCTION_ALREADY_EXISTS) \ \ M(998, POSTGRESQL_CONNECTION_FAILURE) \ M(999, KEEPER_EXCEPTION) \ diff --git a/src/Functions/FunctionFactory.cpp b/src/Functions/FunctionFactory.cpp index 69a34d4d030..8f71db3df7f 100644 --- a/src/Functions/FunctionFactory.cpp +++ b/src/Functions/FunctionFactory.cpp @@ -22,6 +22,7 @@ namespace ErrorCodes { extern const int UNKNOWN_FUNCTION; extern const int LOGICAL_ERROR; + extern const int FUNCTION_ALREADY_EXISTS; } const String & getFunctionCanonicalNameIfAny(const String & name) @@ -140,6 +141,9 @@ void FunctionFactory::registerUserDefinedFunction( const ASTCreateFunctionQuery & create_function_query, CaseSensitiveness case_sensitiveness) { + if (hasNameOrAlias(create_function_query.function_name)) + throw Exception("The function '" + create_function_query.function_name + "' already exists", ErrorCodes::FUNCTION_ALREADY_EXISTS); + registerFunction(create_function_query.function_name, [create_function_query](ContextPtr context) { auto function = UserDefinedFunction::create(context);