diff --git a/modules/ROOT/pages/clauses/create.adoc b/modules/ROOT/pages/clauses/create.adoc index 57843ddae..f07d0a235 100644 --- a/modules/ROOT/pages/clauses/create.adoc +++ b/modules/ROOT/pages/clauses/create.adoc @@ -234,6 +234,7 @@ This is because a relationship can only have exactly one type. ---- .Create nodes and relationships using dynamic node labels and relationship types +// tag::clauses_create_dynamic_create[] [source, cypher] ---- CREATE (greta:$($nodeLabels) {name: 'Greta Gerwig'}) @@ -242,6 +243,7 @@ UNWIND $movies AS movieTitle CREATE (greta)-[rel:$($relType)]->(m:Movie {title: movieTitle}) RETURN greta.name AS name, labels(greta) AS labels, type(rel) AS relType, collect(m.title) AS movies ---- +// end::clauses_create_dynamic_create[] .Result [role="queryresult",options="footer",cols="4*(finish) WHERE start.name = 'A' AND finish.name = 'D' FOREACH (n IN nodes(p) | SET n.marked = true) ---- +// end::clauses_foreach_node[] .Result [role="queryresult",options="footer",cols="1*(finish) +WHERE start.name = 'A' AND finish.name = 'D' +FOREACH ( r IN relationships(p) | SET r.marked = true ) +---- +// end::clauses_foreach_relationship[] + +.Result +[role="queryresult",options="footer",cols="1* Protecting against Cypher injection]). .bands-with-headers.csv -[source, csv, filename="artists-with-headers.csv"] +[source, csv, filename="bands-with-headers.csv"] ---- Id,Label,Name 1,Band,The Beatles @@ -318,12 +322,14 @@ Id,Label,Name ---- .Query -[source, cypher, role=test-skip] +// tag::clauses_load_csv_dynamic_columns[] +[source, cypher] ---- LOAD CSV WITH HEADERS FROM 'file:///bands-with-headers.csv' AS line MERGE (n:$(line.Label) {name: line.Name}) RETURN n AS bandNodes ---- +// end::clauses_load_csv_dynamic_columns[] .Result [role="queryresult",options="header,footer",cols="1*() RETURN type(r) AS relType ---- +// end::clauses_match_relationship_types[] [NOTE] The above query uses the xref:functions/scalar.adoc#functions-type[`type()` function]. @@ -238,11 +250,13 @@ RETURN a, b It is possible to specify the type of a relationship in a relationship pattern by using a colon (`:`) before the relationship type. .Relationship pattern filtering on the `ACTED_IN` relationship type +// tag::clauses_match_relationship[] [source, cypher] ---- MATCH (:Movie {title: 'Wall Street'})<-[:ACTED_IN]-(actor:Person) RETURN actor.name AS actor ---- +// end::clauses_match_relationship[] .Result [source, role="queryresult",options="header,footer",cols="1*(movie:Movie) RETURN path ---- +// end::clauses_match_path[] .Result [role="queryresult",options="header,footer",cols="1*() RETURN relationshipType, count(r) AS relationshipCount ---- +// end::clauses_match_dynamic_match_variable[] + .Result [role="queryresult",options="header,footer",cols="2*(m:Movie {title: movieTitle}) RETURN greta.name AS name, labels(greta) AS labels, type(rel) AS relType, collect(m.title) AS movies ---- +// end::clauses_merge_dynamic_merge[] .Result [role="queryresult",options="footer",cols="4*() RETURN p.name, r ---- +// end::clauses_optional_match[] .Result [role="queryresult",options="header,footer",cols="2*(m) RETURN type(r) ---- +// end::clauses_return_relationship_type[] .Result [role="queryresult",options="header,footer",cols="1*(m) RETURN * ---- +// end::clauses_return_all_elements[] This returns the two nodes, and the two possible paths between them. @@ -149,11 +157,13 @@ d|Rows: 1 Names of returned columns can be renamed using the `AS` operator: .Query +// tag::clauses_return_with_column_alias[] [source, cypher] ---- MATCH (p:Person {name: 'Keanu Reeves'}) RETURN p.nationality AS citizenship ---- +// end::clauses_return_with_column_alias[] Returns the `nationality` property of `'Keanu Reeves'`, but the column is renamed to `citizenship`. @@ -220,11 +230,13 @@ Returns a predicate, a literal and function call with a pattern expression param `DISTINCT` retrieves only unique rows for the columns that have been selected for output. .Query +// tag::clauses_return_distinct[] [source, cypher] ---- MATCH (p:Person {name: 'Keanu Reeves'})-->(m) RETURN DISTINCT m ---- +// end::clauses_return_distinct[] The `Movie` node `'Man of Tai Chi'` is returned by the query, but only once (without the `DISTINCT` operator it would have been returned twice because there are two relationships going to it from `'Keanu Reeves'`): diff --git a/modules/ROOT/pages/clauses/skip.adoc b/modules/ROOT/pages/clauses/skip.adoc index b4c4ecbee..b8436b80d 100644 --- a/modules/ROOT/pages/clauses/skip.adoc +++ b/modules/ROOT/pages/clauses/skip.adoc @@ -69,6 +69,7 @@ d|Rows: 2 The following query returns the middle two rows, with `SKIP` skipping the first and xref:clauses/limit.adoc[`LIMIT`] removing the final two. .Query +// tag::clauses_skip[] [source, cypher] ---- MATCH (n) @@ -77,6 +78,7 @@ ORDER BY n.name SKIP 1 LIMIT 2 ---- +// end::clauses_skip[] .Result [role="queryresult",options="header,footer",cols="1*(f) WHERE k.since < 2000 RETURN f.name AS oldFriend ---- +// end::clauses_where_relationship_property[] .Result [role="queryresult",options="header,footer",cols="1*(b WHERE b:Person) | b.name] AS friends ---- +// end::clauses_where_pattern_comprehension[] .Result [role="queryresult",options="header,footer",cols="1*(:Product {name: 'Chocolate'}) WITH c AS customer RETURN customer.firstName AS chocolateCustomer ---- +// end::clauses_with_new_variable[] .Result [role="queryresult",options="header,footer",cols="1*(product:Product) @@ -144,6 +147,7 @@ RETURN supplier.name AS company, type(r) AS relType, product.name AS product ---- +// end::clauses_with_all_variables[] .Result [role="queryresult",options="header,footer",cols="3*(chocolate:Product {name: 'Chocolate'}) @@ -204,6 +211,7 @@ WITH customer.firstName || ' ' || customer.lastName AS customerFullName, RETURN customerFullName, chocolateNetPrice ---- +// end::clauses_with_bind_values[] .Result [role="queryresult",options="header,footer",cols="2*(p:Product) @@ -274,6 +285,8 @@ RETURN customer, productsBought ORDER BY totalSpent DESC ---- +// end::clauses_with_aggregations[] + .Result [role="queryresult",options="header,footer", cols="3*(p:Product) @@ -403,6 +419,7 @@ RETURN c.firstName AS customer, totalSpent, c.topSpender AS topSpender ---- +// end::clauses_with_ordering_pagination[] [role="queryresult",options="header,footer", cols="3*(p:Product)<-[:BUYS]-(c:Customer) @@ -516,6 +534,7 @@ RETURN s.name AS supplier, totalSales, uniqueCustomers ---- +// end::clauses_with_filtering[] [role="queryresult",options="header,footer", cols="3*(:Station {name: 'Denmark Hill'}) RETURN s.departs AS departureTime ---- +// end::patterns_fixed_length_patterns_path_pattern[] .Result [role="queryresult",options="header,footer",cols="1*(:Station { name: 'Clapham Junction' }) RETURN d.departs AS departureTime, a.arrives AS arrivalTime ---- +// end::patterns_variable_length_patterns_qpp[] + .Result [role="queryresult",options="header,footer",cols="2*` and not the node patterns abutting it. More generally, where a path pattern contained in a quantified path pattern has the following form: @@ -523,6 +529,7 @@ In this example, an inline predicate can be added that takes advantage of the ge To compose the predicate, the xref:functions/spatial.adoc#functions-distance[point.distance()] function is used to compare the distance between the left-hand `Station` (`a`) and the right-hand `Station` (`b`) for each node-pair along the path to the destination `North Dulwich`: .Query +// tag::patterns_variable_length_patterns_predicates_in_qpp[] [source,cypher] ---- MATCH (bfr:Station {name: "London Blackfriars"}), @@ -534,6 +541,8 @@ MATCH p = (bfr) RETURN reduce(acc = 0, r in relationships(p) | round(acc + r.distance, 2)) AS distance ---- +// end::patterns_variable_length_patterns_predicates_in_qpp[] + .Result [role="queryresult",options="header,footer",cols="m"] diff --git a/modules/ROOT/pages/queries/composed-queries/combined-queries.adoc b/modules/ROOT/pages/queries/composed-queries/combined-queries.adoc index 6a54e224f..63c0aa0d1 100644 --- a/modules/ROOT/pages/queries/composed-queries/combined-queries.adoc +++ b/modules/ROOT/pages/queries/composed-queries/combined-queries.adoc @@ -45,6 +45,7 @@ CREATE (johnny:Actor {name: 'Johnny Depp'}), Combining the results from two queries is done using `UNION ALL`. .Query +// tag::clauses_union_all[] [source, cypher] ---- MATCH (n:Actor) @@ -53,6 +54,7 @@ UNION ALL MATCH (n:Movie) RETURN n.title AS name ---- +// end::clauses_union_all[] The combined result is returned, including duplicates. @@ -74,6 +76,7 @@ The combined result is returned, including duplicates. By not including `ALL` in the `UNION`, duplicates are removed from the combined result set. .Query +// tag::clauses_union[] [source, cypher] ---- MATCH (n:Actor) @@ -82,6 +85,7 @@ UNION MATCH (n:Movie) RETURN n.title AS name ---- +// end::clauses_union[] The combined result is returned, without duplicates.