diff --git a/modules/ROOT/pages/clauses/finish.adoc b/modules/ROOT/pages/clauses/finish.adoc index b233b4896..2d3315e13 100644 --- a/modules/ROOT/pages/clauses/finish.adoc +++ b/modules/ROOT/pages/clauses/finish.adoc @@ -3,17 +3,19 @@ [[query-finish]] = FINISH -A query ending in `FINISH` — instead of `RETURN` — has no result but executes all its side effects. +A query ending in `FINISH` -- instead of `RETURN` -- has no result but executes all its side effects. `FINISH` was introduced as part of Cypher's xref:appendix/gql-conformance/index.adoc[]. The following read query successfully executes but has no results: .Query +// tag::clauses_finish_match[] [source, cypher] ---- MATCH (p:Person) FINISH ---- +// end::clauses_finish_match[] The following query has no result but creates one node with the label `Person`: diff --git a/modules/ROOT/pages/clauses/foreach.adoc b/modules/ROOT/pages/clauses/foreach.adoc index b594ecace..2132954e6 100644 --- a/modules/ROOT/pages/clauses/foreach.adoc +++ b/modules/ROOT/pages/clauses/foreach.adoc @@ -33,15 +33,17 @@ CREATE [[foreach-mark-all-nodes-along-a-path]] == Mark all nodes along a path -This query will set the property `marked` to `true` on all nodes along a path. +This query sets the property `marked` to `true` on all nodes along a path. .Query +// tag::clauses_foreach_node[] [source, cypher, indent=0] ---- MATCH p=(start)-[*]->(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*() RETURN type(r) AS relType ---- +// end::clauses_match_relationship_types[] [NOTE] The above query uses the xref:functions/scalar.adoc#functions-type[`type()` function]. @@ -244,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 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 2f31a9f49..47961fd50 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*(b:Person WHERE b.age > minAge) RETURN b.name ---- +// end::clauses_where_in_match_clause[] .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*(f) WHERE k.since < 2000 RETURN f.name, f.age, f.email ---- +// end::clauses_where_relationship_property[] The `name`, `age` and `email` values for `Peter` are returned because `Andy` has known him since before 2000: @@ -218,12 +230,14 @@ The `name` and `age` values for `Timothy` are returned because he is less than 3 Use the `IS NOT NULL` predicate to only include nodes or relationships in which a property exists: .Query +// tag::clauses_where_property_existence[] [source, cypher] ---- MATCH (n:Person) WHERE n.belt IS NOT NULL RETURN n.name, n.belt ---- +// end::clauses_where_property_existence[] The `name` and `belt` values for `Andy` are returned because he is the only one with a `belt` property: @@ -242,6 +256,7 @@ The `name` and `belt` values for `Andy` are returned because he is the only one As `WHERE` is not considered a clause in its own right, its scope is not limited by a `WITH` directly before it. .Query +// tag::clauses_where_with[] [source, cypher] ---- MATCH (n:Person) @@ -249,6 +264,7 @@ WITH n.name as name WHERE n.age = 25 RETURN name ---- +// end::clauses_where_with[] .Result [role="queryresult",options="header,footer",cols="1*(timothy) RETURN other.name, other.age ---- +// end::clauses_where_patterns[] The `name` and `age` values for nodes that have an outgoing relationship to `Timothy` are returned: @@ -618,12 +636,14 @@ To check if an element exists in a list, use the `IN` operator. The below query checks whether a property exists in a literal list: .Query +// tag::clauses_where_lists[] [source, cypher] ---- MATCH (a:Person) WHERE a.name IN ['Peter', 'Timothy'] RETURN a.name, a.age ---- +// end::clauses_where_lists[] .Result [role="queryresult",options="header,footer",cols="2*(otherPerson) WITH *, type(r) AS connectionType RETURN person.name, otherPerson.name, connectionType ---- +// end::clauses_with_wildcard[] This query returns the names of all related persons and the type of relationship between them.