Skip to content

Commit c34eaeb

Browse files
authored
add new exception
1 parent 5140761 commit c34eaeb

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/Functions/caseWithExpression.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace DB
1111
namespace ErrorCodes
1212
{
1313
extern const int TOO_FEW_ARGUMENTS_FOR_FUNCTION;
14+
extern const int BAD_ARGUMENTS;
1415
}
1516

1617
namespace
@@ -38,6 +39,11 @@ class FunctionCaseWithExpression : public IFunction
3839
if (args.empty())
3940
throw Exception(ErrorCodes::TOO_FEW_ARGUMENTS_FOR_FUNCTION, "Function {} expects at least 1 arguments", getName());
4041

42+
/// We expect an even number of arguments, with the first argument being the expression,
43+
/// and the last argument being the ELSE branch, with the rest being pairs of WHEN and THEN branches.
44+
if (args.size() < 4 || args.size() % 2 != 0)
45+
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Function {} expects an even number of arguments: (expr, when1, then1, ..., else)", getName());
46+
4147
/// See the comments in executeImpl() to understand why we actually have to
4248
/// get the return type of a transform function.
4349

0 commit comments

Comments
 (0)