Add new error code for function that already exists and use while trying create user-defined functions

This commit is contained in:
ANDREI STAROVEROV 2021-05-14 00:41:35 +03:00
parent 7f3e5b9166
commit 2643b71393
2 changed files with 5 additions and 0 deletions

View File

@ -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) \

View File

@ -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);