This commit is contained in:
Han Fei 2024-09-18 23:40:33 +02:00 committed by GitHub
commit 873ce7522f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 12 additions and 1 deletions

View File

@ -106,7 +106,7 @@ bool ParserSelectQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
select_query->recursive_with = s_recursive.ignore(pos, expected);
if (!ParserList(std::make_unique<ParserWithElement>(), std::make_unique<ParserToken>(TokenType::Comma))
if (!ParserList(std::make_unique<ParserWithElement>(select_query->recursive_with), std::make_unique<ParserToken>(TokenType::Comma))
.parse(pos, with_expression_list, expected))
return false;
if (with_expression_list->children.empty())

View File

@ -26,6 +26,10 @@ bool ParserWithElement::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
with_element->children.push_back(with_element->subquery);
node = with_element;
}
else if (with_recursive)
{
return false;
}
else
{
pos = old_pos;

View File

@ -10,9 +10,14 @@ namespace DB
*/
class ParserWithElement : public IParserBase
{
public:
explicit ParserWithElement(bool with_recursive_ = false) : with_recursive(with_recursive_) {}
protected:
const char * getName() const override { return "WITH element"; }
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
/// for `WITH RECURSIVE` CTE, we don't allow expression with alias.
bool with_recursive;
};
}

View File

@ -0,0 +1,2 @@
drop table if exists t;
create view t AS (WITH RECURSIVE 42 as ttt SELECT ttt) -- { clientError SYNTAX_ERROR };