You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -601,15 +606,20 @@ The batch size of `2 ROWS` is an example given the small data set used here.
601
606
For larger data sets, you might want to use larger batch sizes, such as `10000 ROWS`.
602
607
====
603
608
609
+
=== Error behaviour [[txs_error_behaviour]]
610
+
Users can choose one of three different option flags to control the behaviour
611
+
in case of an error occurring in any of the inner transactions of `+CALL { ... } IN TRANSACTIONS+`:
604
612
605
-
=== Errors
606
-
607
-
If an error occurs in `+CALL { ... } IN TRANSACTIONS+` the entire query fails and
608
-
both the current inner transaction and the outer transaction are rolled back.
613
+
* `ON ERROR CONTINUE` to ignore a recoverable error and continue the execution of subsequent inner transactions.
614
+
The outer transaction succeeds.
615
+
It will cause the expected variables from the failed inner query to be bound as null for that specific transaction.
616
+
* `ON ERROR BREAK` to ignore a recoverable error and stop the execution of subsequent inner transactions. The outer transaction succeeds.
617
+
It will cause expected variables from the failed inner query to be bound as null for all onward transactions (including the failed one).
618
+
* `ON ERROR FAIL` to acknowledge a recoverable error and stop the execution of subsequent inner transactions. The outer transaction fails. This is the default behaviour if no flag is explicitly specified.
609
619
610
620
[IMPORTANT]
611
621
====
612
-
On error, any previously committed inner transactions remain committed, and are not rolled back.
622
+
On error, any previously committed inner transactions remain committed, and are not rolled back. Any failed inner transactions are rolled back.
613
623
====
614
624
615
625
In the following example, the last subquery execution in the second inner transaction fails
@@ -621,7 +631,7 @@ due to division by zero.
621
631
UNWIND [4, 2, 1, 0] AS i
622
632
CALL {
623
633
WITH i
624
-
CREATE (:Example {num: 100/i})
634
+
CREATE (:Person {num: 100/i})
625
635
} IN TRANSACTIONS OF 2 ROWS
626
636
RETURN i
627
637
----
@@ -637,7 +647,7 @@ When the failure occurred, the first transaction had already been committed, so
637
647
.Query
638
648
[source, cypher]
639
649
----
640
-
MATCH (e:Example)
650
+
MATCH (e:Person)
641
651
RETURN e.num
642
652
----
643
653
@@ -650,6 +660,235 @@ RETURN e.num
650
660
1+d|Rows: 2
651
661
|===
652
662
663
+
In the following example, `ON ERROR CONTINUE` is used after a failed inner transaction to execute the remaining inner transactions and not fail the outer transaction:
664
+
665
+
.Query
666
+
[source, cypher]
667
+
----
668
+
UNWIND [1, 0, 2, 4] AS i
669
+
CALL {
670
+
WITH i
671
+
CREATE (n:Person {num: 100/i}) // Note, fails when i = 0
This happens because an inner transaction with the two first `i` elements (1 and 0)
718
+
was created, and it fails for 0.
719
+
This causes it to be rolled back and the return
720
+
variable is filled with nulls for those two elements.
721
+
722
+
In the following example, `ON ERROR BREAK` is used after a failed inner transaction to not execute the remaining inner transaction and not fail the outer transaction:
723
+
724
+
.Query
725
+
[source, cypher, indent=0]
726
+
----
727
+
UNWIND [1, 0, 2, 4] AS i
728
+
CALL {
729
+
WITH i
730
+
CREATE (n:Person {num: 100/i}) // Note, fails when i = 0
In the following example, `ON ERROR FAIL` is used after the failed inner transaction, to not execute the remaining inner transactions and to fail the outer transaction:
777
+
778
+
.Query
779
+
[source, cypher, indent=0, role=test-fail]
780
+
----
781
+
UNWIND [1, 0, 2, 4] AS i
782
+
CALL {
783
+
WITH i
784
+
CREATE (n:Person {num: 100/i}) // Note, fails when i = 0
785
+
RETURN n
786
+
} IN TRANSACTIONS
787
+
OF 1 ROW
788
+
ON ERROR FAIL
789
+
RETURN n.num;
790
+
----
791
+
792
+
.Error message
793
+
[source, error, role=test-fail]
794
+
----
795
+
/ by zero (Transactions committed: 1)
796
+
----
797
+
798
+
=== Status report
799
+
Users can also report the execution status of the inner transactions by using `REPORT STATUS AS var`.
800
+
This flag is disallowed for `ON ERROR FAIL`. For more information, see <<txs_error_behaviour, error behaviour>>.
801
+
802
+
After each execution of the inner query finishes (successfully or not), a status value is created that records information about the execution and the transaction that executed it:
803
+
804
+
* If the inner execution produces one or more rows as output, then a binding to this status value is added to each row, under the selected variable name.
805
+
* If the inner execution fails then a single row is produced containing a binding to this status value under the selected variable, and null bindings for all variables that should have been returned by the inner query (if any).
806
+
807
+
The status value is a map value with the following fields:
808
+
809
+
* `started`: `true` when the inner transaction was started, `false` otherwise.
810
+
* `committed`, true when the inner transaction changes were successfully committed, false otherwise.
811
+
* `transactionId`: the inner transaction id, or null if the transaction was not started.
812
+
* `errorMessage`, the inner transaction error message, or null in case of no error.
813
+
814
+
Example of reporting status with `ON ERROR CONTINUE`:
815
+
816
+
.Query
817
+
[source, cypher, indent=0, role=test-result-skip]
818
+
----
819
+
UNWIND [1, 0, 2, 4] AS i
820
+
CALL {
821
+
WITH i
822
+
CREATE (n:Person {num: 100/i}) // Note, fails when i = 0
This is due to the all-or-nothing semantics of `MERGE`, which causes the query to fail if there exists a relationship with the given `year` property but there is no match for the full pattern.
639
638
In this example, since no match was found for the pattern, `MERGE` will try to create the full pattern including a relationship with `{year: 1987}`, which will lead to constraint violation error.
0 commit comments