From 676ba498da3b3c4bf64191d564d25da7e116c8d2 Mon Sep 17 00:00:00 2001 From: JPryce-Aklundh Date: Tue, 6 Dec 2022 14:45:41 +0100 Subject: [PATCH 1/3] update restrictions when using with clause in subquery --- modules/ROOT/pages/clauses/call-subquery.adoc | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/modules/ROOT/pages/clauses/call-subquery.adoc b/modules/ROOT/pages/clauses/call-subquery.adoc index 0d7bb5c77..7f4d95bd8 100644 --- a/modules/ROOT/pages/clauses/call-subquery.adoc +++ b/modules/ROOT/pages/clauses/call-subquery.adoc @@ -675,3 +675,29 @@ These are the restrictions on queries that use `+CALL { ... } IN TRANSACTIONS+`: * A `+CALL { ... } IN TRANSACTIONS+` in a `UNION` is not supported. * A `+CALL { ... } IN TRANSACTIONS+` after a write clause is not supported, unless that write clause is inside a `+CALL { ... } IN TRANSACTIONS+`. +Additionally, there are some restrictions that apply when using an importing `WITH` clause in a `CALL` subquery: + +* Only variables imported with the importing `WITH` clause can be used. +* No expressions or aliasing are allowed within the importing `WITH` clause. +* It is not possible to follow an importing `WITH` clause with any of the following clauses: `DISTINCT`, `ORDER BY`, `WHERE`, `SKIP`, and `LIMIT`. + +Attempting any of the above, will throw the following error: `Importing WITH should consist only of simple references to outside variables. +WHERE is not allowed.` + +A solution to the latter restriction, necessary for any filtering or ordering of an importing `WITH` clause, is to declare a second `WITH` clause after the importing `WITH` clause. +This second `WITH` clause will act as a regular `WITH` clause. +For example, the following query will not throw an error: + +.Query +[source, cypher, indent=0] +---- +UNWIND [[1,2],[1,2,3,4],[1,2,3,4,5]] AS l +CALL { + WITH l + WITH size(l) AS size, l AS l + WHERE size > 2 + RETURN l AS largeLists +} +RETURN largeLists +---- + From 39cc95d66de75506355ed52eb693e702846914da Mon Sep 17 00:00:00 2001 From: JPryce-Aklundh Date: Tue, 6 Dec 2022 16:05:26 +0100 Subject: [PATCH 2/3] post-review changes --- modules/ROOT/pages/clauses/call-subquery.adoc | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/modules/ROOT/pages/clauses/call-subquery.adoc b/modules/ROOT/pages/clauses/call-subquery.adoc index 7f4d95bd8..27ca5a4c7 100644 --- a/modules/ROOT/pages/clauses/call-subquery.adoc +++ b/modules/ROOT/pages/clauses/call-subquery.adoc @@ -681,10 +681,29 @@ Additionally, there are some restrictions that apply when using an importing `WI * No expressions or aliasing are allowed within the importing `WITH` clause. * It is not possible to follow an importing `WITH` clause with any of the following clauses: `DISTINCT`, `ORDER BY`, `WHERE`, `SKIP`, and `LIMIT`. -Attempting any of the above, will throw the following error: `Importing WITH should consist only of simple references to outside variables. -WHERE is not allowed.` +Attempting any of the above, will throw an error. +For example, the following query using a `WHERE` clause after an importing `WITH` clause will throw an error: -A solution to the latter restriction, necessary for any filtering or ordering of an importing `WITH` clause, is to declare a second `WITH` clause after the importing `WITH` clause. +.Query +[source, cypher, indent=0] +---- +UNWIND [[1,2],[1,2,3,4],[1,2,3,4,5]] AS l +CALL { + WITH size(l) AS size, l AS l + WHERE size > 2 + RETURN l AS largeLists +} +RETURN largeLists +---- + +.Error message: +[source, output, role="noheader", indent=0] +---- +Importing WITH should consist only of simple references to outside variables. +WHERE is not allowed. +---- + +A solution to this restriction, necessary for any filtering or ordering of an importing `WITH` clause, is to declare a second `WITH` clause after the importing `WITH` clause. This second `WITH` clause will act as a regular `WITH` clause. For example, the following query will not throw an error: From 4a19599b9671e30c1e2b40df95afe98254e58c11 Mon Sep 17 00:00:00 2001 From: JPryce-Aklundh Date: Tue, 6 Dec 2022 16:27:49 +0100 Subject: [PATCH 3/3] post-review fix 2 --- modules/ROOT/pages/clauses/call-subquery.adoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/ROOT/pages/clauses/call-subquery.adoc b/modules/ROOT/pages/clauses/call-subquery.adoc index 27ca5a4c7..8debd0706 100644 --- a/modules/ROOT/pages/clauses/call-subquery.adoc +++ b/modules/ROOT/pages/clauses/call-subquery.adoc @@ -689,9 +689,9 @@ For example, the following query using a `WHERE` clause after an importing `WITH ---- UNWIND [[1,2],[1,2,3,4],[1,2,3,4,5]] AS l CALL { - WITH size(l) AS size, l AS l - WHERE size > 2 - RETURN l AS largeLists + WITH l + WHERE size(l) > 2 + RETURN l AS largeLists } RETURN largeLists ----