From 2c815356c1c2a226681610edfd8436f38e2a78a8 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Thu, 27 Jul 2017 22:25:52 +0300 Subject: [PATCH] Fixed regression in parsing of CAST [#CLICKHOUSE-3180]. --- dbms/src/Parsers/ExpressionElementParsers.cpp | 4 ++++ dbms/tests/queries/0_stateless/00483_cast_syntax.reference | 2 ++ dbms/tests/queries/0_stateless/00483_cast_syntax.sql | 2 ++ 3 files changed, 8 insertions(+) create mode 100644 dbms/tests/queries/0_stateless/00483_cast_syntax.reference create mode 100644 dbms/tests/queries/0_stateless/00483_cast_syntax.sql diff --git a/dbms/src/Parsers/ExpressionElementParsers.cpp b/dbms/src/Parsers/ExpressionElementParsers.cpp index fa43d5fba01..34198b58fd5 100644 --- a/dbms/src/Parsers/ExpressionElementParsers.cpp +++ b/dbms/src/Parsers/ExpressionElementParsers.cpp @@ -300,6 +300,8 @@ bool ParserCastExpression::parseImpl(Pos & pos, ASTPtr & node, Expected & expect return false; const auto & id = typeid_cast(*identifier).name; + + /// TODO This is ridiculous. Please get rid of this. if (id.length() != strlen(name) || 0 != strcasecmp(id.c_str(), name)) { /// Parse as a CASE expression. @@ -340,6 +342,8 @@ bool ParserCastExpression::parseImpl(Pos & pos, ASTPtr & node, Expected & expect } else { + pos = contents_begin; + /// CAST(expression, 'type') /// Reparse argument list from scratch ParserExpressionWithOptionalAlias expression{false}; diff --git a/dbms/tests/queries/0_stateless/00483_cast_syntax.reference b/dbms/tests/queries/0_stateless/00483_cast_syntax.reference new file mode 100644 index 00000000000..6ed281c757a --- /dev/null +++ b/dbms/tests/queries/0_stateless/00483_cast_syntax.reference @@ -0,0 +1,2 @@ +1 +1 diff --git a/dbms/tests/queries/0_stateless/00483_cast_syntax.sql b/dbms/tests/queries/0_stateless/00483_cast_syntax.sql new file mode 100644 index 00000000000..be248fce394 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00483_cast_syntax.sql @@ -0,0 +1,2 @@ +SELECT CAST(1 AS Int8); +SELECT CAST(1, 'Int8');