diff --git a/src/query/frontend/ast/cypher_main_visitor.cpp b/src/query/frontend/ast/cypher_main_visitor.cpp index c9ca477c9..e31c65931 100644 --- a/src/query/frontend/ast/cypher_main_visitor.cpp +++ b/src/query/frontend/ast/cypher_main_visitor.cpp @@ -1752,7 +1752,11 @@ antlrcpp::Any CypherMainVisitor::visitReturnBody(MemgraphCypher::ReturnBodyConte body.skip = static_cast<Expression *>(std::any_cast<Expression *>(ctx->skip()->accept(this))); } if (ctx->limit()) { - body.limit = static_cast<Expression *>(std::any_cast<Expression *>(ctx->limit()->accept(this))); + if (ctx->limit()->expression()) { + body.limit = std::any_cast<Expression *>(ctx->limit()->accept(this)); + } else { + body.limit = std::any_cast<ParameterLookup *>(ctx->limit()->accept(this)); + } } std::tie(body.all_identifiers, body.named_expressions) = std::any_cast<std::pair<bool, std::vector<NamedExpression *>>>(ctx->returnItems()->accept(this)); diff --git a/src/query/frontend/opencypher/grammar/Cypher.g4 b/src/query/frontend/opencypher/grammar/Cypher.g4 index f4830ccef..55cb53ef3 100644 --- a/src/query/frontend/opencypher/grammar/Cypher.g4 +++ b/src/query/frontend/opencypher/grammar/Cypher.g4 @@ -143,7 +143,7 @@ order : ORDER BY sortItem ( ',' sortItem )* ; skip : L_SKIP expression ; -limit : LIMIT expression ; +limit : LIMIT ( expression | parameter ) ; sortItem : expression ( ASCENDING | ASC | DESCENDING | DESC )? ; diff --git a/tests/gql_behave/tests/memgraph_V1/features/parameters.feature b/tests/gql_behave/tests/memgraph_V1/features/parameters.feature index 288f93206..d9b25ff8c 100644 --- a/tests/gql_behave/tests/memgraph_V1/features/parameters.feature +++ b/tests/gql_behave/tests/memgraph_V1/features/parameters.feature @@ -153,3 +153,20 @@ Feature: Parameters Then the result should be: | a | | (:Label1 {x: 10}) | + + Scenario: Parameters for limit in return returnBody + Given an empty graph + And having executed: + """ + FOREACH (id IN range(1, 10) | CREATE (:Node {id: id})) + """ + And parameters are: + | limit | 2 | + When executing query: + """ + MATCH (n) RETURN n LIMIT $limit + """ + Then the result should be: + | n | + | (:Node {id: 1}) | + | (:Node {id: 2}) |