Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion modules/ROOT/pages/clauses/finish.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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`:

Expand Down
48 changes: 47 additions & 1 deletion modules/ROOT/pages/clauses/foreach.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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*<m"]
Expand All @@ -51,3 +53,47 @@ d|Rows: 0 +
Properties set: 4
|===


[[foreach-mark-all-relationships-along-a-path]]
== Mark all relationships along a path

This query sets the property `marked` to `true` on all relationships along a path.

// tag::clauses_foreach_relationship[]
[source, cypher, indent=0]
----
MATCH p=(start)-[*]->(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*<m"]
|===
|(empty result)
d|Rows: 0 +
Properties set: 3
|===

[[foreach-create-new-nodes-form-a-list]]
== Create new nodes from a list of name labels

This query creates a new node for each label in a list.

.Query
// tag::clauses_foreach_create[]
[source, cypher, indent=0]
----
WITH ['E', 'F', 'G'] AS names
FOREACH ( value IN names | CREATE (:Person {name: value}) )
----
// end::clauses_foreach_create[]

.Result
[role="queryresult",options="footer",cols="1*<m"]
|===
1+|(empty result)
1+d|Rows: 0 +
Nodes created: 3
|===
4 changes: 4 additions & 0 deletions modules/ROOT/pages/clauses/limit.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,14 @@ Properties set: 1
`LIMIT` can be used as a standalone clause, or in conjunction with xref:clauses/order-by.adoc[`ORDER BY`] or xref:clauses/skip.adoc[`SKIP`]/xref:clauses/skip.adoc#offset-synonym[`OFFSET`].

.Standalone use of `LIMIT`
// tag::clauses_limit_standalone[]
[source, cypher]
----
MATCH (n)
LIMIT 2
RETURN collect(n.name) AS names
----
// end::clauses_limit_standalone[]

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
Expand All @@ -185,6 +187,7 @@ The following query orders all nodes by `name` descending, skips the two first r
It then xref:functions/aggregating.adoc#functions-collect[collects] the results in a list.

.`LIMIT` used in conjunction with `ORDER BY` and `SKIP`
// tag::clauses_limit[]
[source, cypher]
----
MATCH (n)
Expand All @@ -193,6 +196,7 @@ SKIP 2
LIMIT 2
RETURN collect(n.name) AS names
----
// end::clauses_limit[]

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
Expand Down
16 changes: 15 additions & 1 deletion modules/ROOT/pages/clauses/load-csv.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ By default, paths are resolved relative to the Neo4j import directory.
----

.Query
// tag::clauses_load_csv_local_files[]
[source, cypher]
----
LOAD CSV FROM 'file:///artists.csv' AS row
MERGE (a:Artist {name: row[1], year: toInteger(row[2])})
RETURN a.name, a.year
----
// end::clauses_load_csv_local_files[]

.Result
[role="queryresult",options="header,footer",cols="2*<m"]
Expand Down Expand Up @@ -112,12 +114,14 @@ However, this means that insecure URLs on virtual hosts will not function unless
----

.Query
// tag::clauses_load_csv_remote_locations[]
[source, cypher]
----
LOAD CSV FROM 'https://data.neo4j.com/bands/artists.csv' AS row
MERGE (a:Artist {name: row[1], year: toInteger(row[2])})
RETURN a.name, a.year
----
// end::clauses_load_csv_remote_locations[]

.Result
[role="queryresult",options="header,footer",cols="2*<m"]
Expand Down Expand Up @@ -705,10 +709,11 @@ person_tmdbId,bio,born,bornIn,died,person_imdbId,name,person_poster,person_url
----

[NOTE]
The below query uses a xref:subqueries/call-subquery.adoc#variable-scope-clause[variable scope clause] (introduced in Neo4j 5.23) to import variables into the `CALL` subquery.
The query below uses a xref:subqueries/call-subquery.adoc#variable-scope-clause[variable scope clause] (introduced in Neo4j 5.23) to import variables into the `CALL` subquery.
If you are using an older version of Neo4j, use an xref:subqueries/call-subquery.adoc#importing-with[importing `WITH` clause] instead.

.Query
// tag::clauses_load_csv_transactions[]
[source, cypher]
----
LOAD CSV WITH HEADERS FROM 'https://data.neo4j.com/importing-cypher/persons.csv' AS row
Expand All @@ -717,6 +722,7 @@ CALL (row) {
SET p.name = row.name, p.born = row.born
} IN TRANSACTIONS OF 200 ROWS
----
// end::clauses_load_csv_transactions[]

.Result
[source, role="queryresult"]
Expand Down Expand Up @@ -751,11 +757,13 @@ A common use case for this function is to generate sequential unique IDs for CSV
----

.Query
// tag::clauses_load_csv_linenumber[]
[source, cypher]
----
LOAD CSV FROM 'file:///artists.csv' AS row
RETURN linenumber() AS number, row
----
// end::clauses_load_csv_linenumber[]

.Result
[role="queryresult",options="header,footer",cols="2*<m"]
Expand Down Expand Up @@ -786,11 +794,13 @@ The xref:functions/load-csv.adoc#functions-file[`file()`] function provides the
----

.Query
// tag::clauses_load_csv_file[]
[source, cypher, role=test-result-skip]
----
LOAD CSV FROM 'file:///artists.csv' AS row
RETURN DISTINCT file() AS path
----
// end::clauses_load_csv_file[]

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
Expand Down Expand Up @@ -837,6 +847,7 @@ Id,Name,Year
----

.Query
// tag::clauses_load_csv_headers[]
[source, cypher]
----
LOAD CSV WITH HEADERS FROM 'file:///artists-with-headers.csv' AS row
Expand All @@ -845,6 +856,7 @@ RETURN
a.name AS name,
a.year AS year
----
// end::clauses_load_csv_headers[]

.Result
[role="queryresult",options="header,footer",cols="2*<m"]
Expand Down Expand Up @@ -880,11 +892,13 @@ If you try to import a file that doesn't use `,` as field delimiter and you also
----

.Query
// tag::clauses_load_csv_field_terminator[]
[source, cypher]
----
LOAD CSV FROM 'file:///artists-fieldterminator.csv' AS row FIELDTERMINATOR ';'
MERGE (:Artist {name: row[1], year: toInteger(row[2])})
----
// end::clauses_load_csv_field_terminator[]

.Result
[source, role="queryresult"]
Expand Down
10 changes: 10 additions & 0 deletions modules/ROOT/pages/clauses/match.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ For more information about finding node patterns, see xref:patterns/fixed-length
By specifying a pattern with a single node and no labels, all nodes in the graph will be returned.

.Find all nodes in a graph
// tag::clauses_match_all_nodes[]
[source, cypher]
----
MATCH (n)
RETURN n
----
// end::clauses_match_all_nodes[]

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
Expand All @@ -70,11 +72,13 @@ RETURN n
=== Find nodes with a specific label

.Find all nodes with the `Movie` label
// tag::clauses_match_label[]
[source, cypher]
----
MATCH (movie:Movie)
RETURN movie.title
----
// end::clauses_match_label[]

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
Expand Down Expand Up @@ -195,11 +199,13 @@ RETURN movie.title AS movieTitle
It is possible to introduce a variable to a pattern, either for filtering on relationship properties or to return a relationship.

.Find the types of an aliased relationship
// tag::clauses_match_relationship_types[]
[source, cypher]
----
MATCH (:Person {name: 'Oliver Stone'})-[r]->()
RETURN type(r) AS relType
----
// end::clauses_match_relationship_types[]

[NOTE]
The above query uses the xref:functions/scalar.adoc#functions-type[`type()` function].
Expand Down Expand Up @@ -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*<m"]
Expand Down Expand Up @@ -400,11 +408,13 @@ For more information about how to set parameters, see xref:syntax/parameters.ado
The `MATCH` clause can also be used to bind whole paths to variables.

.Find all paths matching a pattern
// tag::clauses_match_path[]
[source, cypher]
----
MATCH path = ()-[:ACTED_IN]->(movie:Movie)
RETURN path
----
// end::clauses_match_path[]

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
Expand Down
2 changes: 2 additions & 0 deletions modules/ROOT/pages/clauses/optional-match.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ This is because the second `MATCH` clause returns no data (there are no `DIRECTE
However, replacing the second `MATCH` clause with `OPTIONAL MATCH` does return results.
This is because, unlike `MATCH`, `OPTIONAL MATCH` enables the value `null` to be passed between clauses.

// tag::clauses_optional_match[]
[source, cypher]
----
MATCH (p:Person {name: 'Martin Sheen'})
OPTIONAL MATCH (p)-[r:DIRECTED]->()
RETURN p.name, r
----
// end::clauses_optional_match[]

.Result
[role="queryresult",options="header,footer",cols="2*<m"]
Expand Down
8 changes: 8 additions & 0 deletions modules/ROOT/pages/clauses/order-by.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ CREATE
`ORDER BY` is used to sort the output.

.Query
// tag::clauses_order_by[]
[source, cypher]
----
MATCH (n)
RETURN n.name, n.age
ORDER BY n.name
----
// end::clauses_order_by[]

The nodes are returned, sorted by their name.

Expand All @@ -67,12 +69,14 @@ You can order by multiple properties by stating each variable in the `ORDER BY`
Cypher will sort the result by the first variable listed, and for equals values, go to the next property in the `ORDER BY` clause, and so on.

.Query
// tag::clauses_order_by_multiple[]
[source, cypher]
----
MATCH (n)
RETURN n.name, n.age
ORDER BY n.age, n.name
----
// end::clauses_order_by_multiple[]

This returns the nodes, sorted first by their age, and then by their name.

Expand Down Expand Up @@ -246,12 +250,14 @@ Read more about this capability in xref::indexes/search-performance-indexes/usin


.Standalone use of `ORDER BY`
// tag::clauses_order_by_standalone[]
[source, cypher]
----
MATCH (n)
ORDER BY n.name
RETURN collect(n.name) AS names
----
// end::clauses_order_by_standalone[]

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
Expand All @@ -264,6 +270,7 @@ RETURN collect(n.name) AS names
The following query orders all nodes by `name` descending, skips the first row and limits the results to one row.

.`ORDER BY` used in conjunction with `SKIP` and `LIMIT`
// tag::clauses_order_by_descending[]
[source, cypher]
----
MATCH (n)
Expand All @@ -272,6 +279,7 @@ SKIP 1
LIMIT 1
RETURN n.name AS name
----
// end::clauses_order_by_descending[]

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
Expand Down
Loading
Loading