Skip to content

Commit

Permalink
Merge pull request #2920 from VadimPE/CLICKHOUSE-3819
Browse files Browse the repository at this point in the history
CLICKHOUSE-3819 add CASE without ELSE
  • Loading branch information
alexey-milovidov authored Aug 22, 2018
2 parents aaf218d + 4f7b8fd commit 5c1925a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
16 changes: 11 additions & 5 deletions dbms/src/Parsers/ParserCase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 (!p_expr.parse(pos, expr_else, expected))
return false;
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))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
0
\N
0
\N
9 changes: 9 additions & 0 deletions dbms/tests/queries/0_stateless/00688_case_without_else.sql
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 5c1925a

Please sign in to comment.