From e42f85a81cded34f3c37d04db64c00c513764a4e Mon Sep 17 00:00:00 2001 From: Arne Fischereit <79841228+arnefischereit@users.noreply.github.com> Date: Fri, 8 Sep 2023 09:17:26 +0200 Subject: [PATCH] Restructure the main part of create.adoc (#670) --- modules/ROOT/pages/clauses/create.adoc | 247 ++++++------------------- modules/ROOT/pages/clauses/set.adoc | 2 +- 2 files changed, 62 insertions(+), 187 deletions(-) diff --git a/modules/ROOT/pages/clauses/create.adoc b/modules/ROOT/pages/clauses/create.adoc index 081f645f1..91ac28b5b 100644 --- a/modules/ROOT/pages/clauses/create.adoc +++ b/modules/ROOT/pages/clauses/create.adoc @@ -3,247 +3,122 @@ [[query-create]] = CREATE -[abstract] --- -The `CREATE` clause is used to create nodes and relationships. --- +== Introduction +The `CREATE` clause allows you to create nodes and relationships. +To define these entities, `CREATE` uses a syntax similar to that of xref::clauses/match.adoc[`MATCH`]. +However, while xref::patterns/index.adoc[patterns] only need to evaluate to either true or false, the syntax for `CREATE` needs to specify exactly what nodes and relationships to create. [[create-nodes]] -== Create nodes +== Syntax for nodes -[[create-create-single-node]] -=== Create single node - -Creating a single node is done by issuing the following query: - -.Query -[source, cypher, indent=0] ----- -CREATE (n) ----- - -.Result -[role="queryresult",options="footer",cols="1*(wallStreet:Movie {title: 'Wall Street'})<-[:DIRECTED]-(oliver:Person:Director {name: 'Oliver Stone'}) ---- -.Result -[role="queryresult",options="footer",cols="1*(wallStreet:Movie {title: 'Wall Street'})<-[:DIRECTED]-(oliver) ---- -.Result -[role="queryresult",options="footer",cols="1*(wallStreet:Movie {title: 'Wall Street'})<-[:DIRECTED]-(oliver:Person:Director {name: 'Oliver Stone'}), (wallStreet)<-[:ACTED_IN {role: 'Gordon Gekko'}]-(michael:Person:Actor {name: 'Michael Douglas'}) +RETURN length(p) ---- -.Result -[role="queryresult",options="footer",cols="1*(b) -RETURN type(r) +{ + "age": 23 +} ---- - -The created relationship is returned by the query. - -.Result -[role="queryresult",options="header,footer",cols="1*' + b.name}]->(b) -RETURN type(r), r.name +MATCH (person:Person) + WHERE person.name IS NOT NULL +CREATE (anotherPerson:Person {name: person.name, age: $age}) ---- -The type and name of the newly-created relationship is returned by the example query. - -.Result -[role="queryresult",options="header,footer",cols="2*B"+ -2+d|Rows: 1 + -Relationships created: 1 + -Properties set: 1 -|=== - +This example created a `Person` node with the same name as another person and the age from a xref:syntax/parameters.adoc[parameter] called `age`. -[[create-create-a-full-path]] -== Create a full path - -When you use `CREATE` and a pattern, all parts of the pattern that are not already in scope at this time will be created. +Such an expression may not contain a reference to a variable that is defined in the same `CREATE` statement. +This is to ensure that the value of a property is always clear. .Query -[source, cypher] +[source, cypher, role=test-fail] ---- -CREATE p = (:Person {name:'Andy'})-[:WORKS_AT]->(:Company {name: 'Neo4j'})<-[:WORKS_AT]-(:Person {name: 'Michael'}) -RETURN p +CREATE (charlie {score: oliver.score + 1}), (oliver {score: charlie.score + 1}) ---- -This query creates three nodes and two relationships in one go, assigns it to a path variable, and returns it. - -.Result -[role="queryresult",options="header,footer",cols="1*(:Company {name: "Neo4j"})<-[:WORKS_AT]-(:Person {name: "Michael"}) -1+d|Rows: 1 + -Nodes created: 3 + -Relationships created: 2 + -Properties set: 2 -|=== - +This query tries to create nodes such that Charlie's score is higher than Oliver's and vice versa, which is a contradiction. +The query therefore fails. [[use-parameters-with-create]] == Use parameters with `CREATE` diff --git a/modules/ROOT/pages/clauses/set.adoc b/modules/ROOT/pages/clauses/set.adoc index 35cfc804a..27340b5a2 100644 --- a/modules/ROOT/pages/clauses/set.adoc +++ b/modules/ROOT/pages/clauses/set.adoc @@ -367,7 +367,7 @@ CREATE ---- //// -xref::clauses/set.adoc#set-remove-properties-using-empty-map[In contrast to the property replacement operator `=`], providing an empty map as the right operand to `+=` will not remove any existing properties from a node or relationship. +xref:clauses/set.adoc#set-remove-properties-using-empty-map[In contrast to the property replacement operator `=`], providing an empty map as the right operand to `+=` will not remove any existing properties from a node or relationship. In line with the semantics detailed above, passing in an empty map with `+=` will have no effect: .Query