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
Copy file name to clipboardExpand all lines: modules/ROOT/pages/clauses/merge.adoc
+6-5Lines changed: 6 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -328,8 +328,9 @@ Instead, a new `Movie` node is created.
328
328
[[merge-merge-on-an-undirected-relationship]]
329
329
=== Merge on an undirected relationship
330
330
331
-
`MERGE` can also be used with an undirected relationship.
332
-
When it needs to create a new one, it will pick a direction.
331
+
`MERGE` can also be used without specifying the direction of a relationship.
332
+
Cypher will first try to xref:clauses/match.adoc#_match_on_an_undirected_relationship[match the relationship in both directions].
333
+
If the relationship does not exist in either direction, it will create one left to right.
333
334
334
335
.Query
335
336
[source, cypher]
@@ -342,7 +343,7 @@ RETURN r
342
343
----
343
344
344
345
As `'Charlie Sheen'` and `'Oliver Stone'` do not know each other in the example graph, this `MERGE` query will create a `KNOWS` relationship between them.
345
-
The direction of the created relationship is arbitrary.
346
+
The direction of the created relationship is left to right.
346
347
347
348
.Result
348
349
[role="queryresult",options="header",cols="1*<m"]
@@ -534,13 +535,13 @@ However, for relationship uniqueness constraints there are some additional thing
534
535
535
536
For example, if there exists a relationship uniqueness constraint on `()-[:ACTED_IN(year)]-()`, then the following query, in which not all nodes of the pattern are bound, would fail:
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.
545
546
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