Better exception message in case of wrong number of arguments for function "if" [#CLICKHOUSE-3932]

This commit is contained in:
Alexey Milovidov 2018-08-24 12:57:42 +03:00
parent 5637b30556
commit eee6644a22
3 changed files with 11 additions and 3 deletions

View File

@ -423,10 +423,13 @@ void ExpressionAnalyzer::optimizeIfWithConstantConditionImpl(ASTPtr & current_as
optimizeIfWithConstantConditionImpl(function_node->arguments, aliases);
ASTExpressionList * args = typeid_cast<ASTExpressionList *>(function_node->arguments.get());
ASTPtr condition_expr = args->children.at(0);
ASTPtr then_expr = args->children.at(1);
ASTPtr else_expr = args->children.at(2);
if (args->children.size() != 3)
throw Exception("Wrong number of arguments for function 'if' (" + toString(args->children.size()) + " instead of 3)",
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
ASTPtr condition_expr = args->children[0];
ASTPtr then_expr = args->children[1];
ASTPtr else_expr = args->children[2];
bool condition;
if (tryExtractConstValueFromCondition(condition_expr, condition))

View File

@ -0,0 +1,4 @@
SELECT if(); -- { serverError 42 }
SELECT if(1); -- { serverError 42 }
SELECT if(1, 1); -- { serverError 42 }
SELECT if(1, 1, 1);