From 76a591fa5e1f2e4974af78fb40f5ba04308f496a Mon Sep 17 00:00:00 2001 From: Nikolay Degterinsky Date: Mon, 1 May 2023 15:16:12 +0000 Subject: [PATCH] Allow restricted keywords if alias is quoted --- src/Parsers/ExpressionElementParsers.cpp | 4 +++- .../02725_alias_with_restricted_keywords.reference | 1 + .../0_stateless/02725_alias_with_restricted_keywords.sql | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 tests/queries/0_stateless/02725_alias_with_restricted_keywords.reference create mode 100644 tests/queries/0_stateless/02725_alias_with_restricted_keywords.sql diff --git a/src/Parsers/ExpressionElementParsers.cpp b/src/Parsers/ExpressionElementParsers.cpp index a6354cd0e81..28cef51e571 100644 --- a/src/Parsers/ExpressionElementParsers.cpp +++ b/src/Parsers/ExpressionElementParsers.cpp @@ -1429,10 +1429,12 @@ bool ParserAlias::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) if (!allow_alias_without_as_keyword && !has_as_word) return false; + bool is_quoted = pos->type == TokenType::QuotedIdentifier; + if (!id_p.parse(pos, node, expected)) return false; - if (!has_as_word) + if (!has_as_word && !is_quoted) { /** In this case, the alias can not match the keyword - * so that in the query "SELECT x FROM t", the word FROM was not considered an alias, diff --git a/tests/queries/0_stateless/02725_alias_with_restricted_keywords.reference b/tests/queries/0_stateless/02725_alias_with_restricted_keywords.reference new file mode 100644 index 00000000000..9874d6464ab --- /dev/null +++ b/tests/queries/0_stateless/02725_alias_with_restricted_keywords.reference @@ -0,0 +1 @@ +1 2 diff --git a/tests/queries/0_stateless/02725_alias_with_restricted_keywords.sql b/tests/queries/0_stateless/02725_alias_with_restricted_keywords.sql new file mode 100644 index 00000000000..6df0e856061 --- /dev/null +++ b/tests/queries/0_stateless/02725_alias_with_restricted_keywords.sql @@ -0,0 +1 @@ +SELECT 1 `array`, 2 "union";