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
2 changes: 2 additions & 0 deletions modules/ROOT/pages/clauses/create.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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'})
Expand All @@ -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*<m"]
Expand Down
4 changes: 3 additions & 1 deletion modules/ROOT/pages/clauses/finish.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,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
20 changes: 18 additions & 2 deletions 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 @@ -308,7 +312,7 @@ It also mitigates the risk of Cypher injection.
(For more information about Cypher injection, see link:https://neo4j.com/developer/kb/protecting-against-cypher-injection/[Neo4j Knowledge Base -> 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
Expand All @@ -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*<m"]
Expand Down Expand Up @@ -705,6 +711,7 @@ person_tmdbId,bio,born,bornIn,died,person_imdbId,name,person_poster,person_url
The below query uses a xref:subqueries/call-subquery.adoc#variable-scope-clause[variable scope clause] to import variables into the `CALL` subquery.
.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 @@ -713,6 +720,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 @@ -747,11 +755,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 @@ -782,11 +792,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 @@ -833,6 +845,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 @@ -841,6 +854,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 @@ -876,11 +890,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
Loading