CLICKHOUSE-3819 add CASE without ELSE

This commit is contained in:
VadimPE 2018-08-22 18:17:40 +03:00
parent 88f1346be4
commit 9e485dae1e
3 changed files with 24 additions and 5 deletions

View File

@ -50,12 +50,18 @@ bool ParserCase::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
if (!has_branch)
return false;
if (!s_else.ignore(pos, expected))
return false;
ASTPtr expr_else;
if (s_else.ignore(pos, expected))
{
if (!p_expr.parse(pos, expr_else, expected))
return false;
}
else
{
Field field_with_null;
ASTLiteral null_literal(field_with_null);
expr_else = std::make_shared<ASTLiteral>(null_literal);
}
args.push_back(expr_else);
if (!s_end.ignore(pos, expected))

View File

@ -0,0 +1,4 @@
0
NULL
0
NULL

View File

@ -0,0 +1,9 @@
DROP TABLE IF EXISTS test.test;
CREATE TABLE test.test (a UInt8) ENGINE = Memory;
INSERT INTO test.test VALUES (1), (2), (1), (3);
SELECT CASE WHEN a=1 THEN 0 END FROM test.test;
DROP TABLE test.test;