Skip to content

Commit d20cb4b

Browse files
authored
tags for clause section (#1138)
1 parent 09ee930 commit d20cb4b

File tree

8 files changed

+94
-4
lines changed

8 files changed

+94
-4
lines changed

modules/ROOT/pages/clauses/finish.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33
[[query-finish]]
44
= FINISH
55

6-
A query ending in `FINISH` instead of `RETURN` has no result but executes all its side effects.
6+
A query ending in `FINISH` -- instead of `RETURN` -- has no result but executes all its side effects.
77
`FINISH` was introduced as part of Cypher's xref:appendix/gql-conformance/index.adoc[].
88

99
The following read query successfully executes but has no results:
1010

1111
.Query
12+
// tag::clauses_finish_match[]
1213
[source, cypher]
1314
----
1415
MATCH (p:Person)
1516
FINISH
1617
----
18+
// end::clauses_finish_match[]
1719

1820
The following query has no result but creates one node with the label `Person`:
1921

modules/ROOT/pages/clauses/foreach.adoc

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,17 @@ CREATE
3333
[[foreach-mark-all-nodes-along-a-path]]
3434
== Mark all nodes along a path
3535

36-
This query will set the property `marked` to `true` on all nodes along a path.
36+
This query sets the property `marked` to `true` on all nodes along a path.
3737

3838
.Query
39+
// tag::clauses_foreach_node[]
3940
[source, cypher, indent=0]
4041
----
4142
MATCH p=(start)-[*]->(finish)
4243
WHERE start.name = 'A' AND finish.name = 'D'
4344
FOREACH (n IN nodes(p) | SET n.marked = true)
4445
----
46+
// end::clauses_foreach_node[]
4547

4648
.Result
4749
[role="queryresult",options="footer",cols="1*<m"]
@@ -51,3 +53,47 @@ d|Rows: 0 +
5153
Properties set: 4
5254
|===
5355

56+
57+
[[foreach-mark-all-relationships-along-a-path]]
58+
== Mark all relationships along a path
59+
60+
This query sets the property `marked` to `true` on all relationships along a path.
61+
62+
// tag::clauses_foreach_relationship[]
63+
[source, cypher, indent=0]
64+
----
65+
MATCH p=(start)-[*]->(finish)
66+
WHERE start.name = 'A' AND finish.name = 'D'
67+
FOREACH ( r IN relationships(p) | SET r.marked = true )
68+
----
69+
// end::clauses_foreach_relationship[]
70+
71+
.Result
72+
[role="queryresult",options="footer",cols="1*<m"]
73+
|===
74+
|(empty result)
75+
d|Rows: 0 +
76+
Properties set: 3
77+
|===
78+
79+
[[foreach-create-new-nodes-form-a-list]]
80+
== Create new nodes from a list of name labels
81+
82+
This query creates a new node for each label in a list.
83+
84+
.Query
85+
// tag::clauses_foreach_create[]
86+
[source, cypher, indent=0]
87+
----
88+
WITH ['E', 'F', 'G'] AS names
89+
FOREACH ( value IN names | CREATE (:Person {name: value}) )
90+
----
91+
// end::clauses_foreach_create[]
92+
93+
.Result
94+
[role="queryresult",options="footer",cols="1*<m"]
95+
|===
96+
1+|(empty result)
97+
1+d|Rows: 0 +
98+
Nodes created: 3
99+
|===

modules/ROOT/pages/clauses/limit.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,14 @@ Properties set: 1
166166
`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`].
167167

168168
.Standalone use of `LIMIT`
169+
// tag::clauses_limit_standalone[]
169170
[source, cypher]
170171
----
171172
MATCH (n)
172173
LIMIT 2
173174
RETURN collect(n.name) AS names
174175
----
176+
// end::clauses_limit_standalone[]
175177

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

187189
.`LIMIT` used in conjunction with `ORDER BY` and `SKIP`
190+
// tag::clauses_limit[]
188191
[source, cypher]
189192
----
190193
MATCH (n)
@@ -193,6 +196,7 @@ SKIP 2
193196
LIMIT 2
194197
RETURN collect(n.name) AS names
195198
----
199+
// end::clauses_limit[]
196200

197201
.Result
198202
[role="queryresult",options="header,footer",cols="1*<m"]

modules/ROOT/pages/clauses/load-csv.adoc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ By default, paths are resolved relative to the Neo4j import directory.
4646
----
4747
4848
.Query
49+
// tag::clauses_load_csv_local_files[]
4950
[source, cypher]
5051
----
5152
LOAD CSV FROM 'file:///artists.csv' AS row
5253
MERGE (a:Artist {name: row[1], year: toInteger(row[2])})
5354
RETURN a.name, a.year
5455
----
56+
// end::clauses_load_csv_local_files[]
5557
5658
.Result
5759
[role="queryresult",options="header,footer",cols="2*<m"]
@@ -112,12 +114,14 @@ However, this means that insecure URLs on virtual hosts will not function unless
112114
----
113115
114116
.Query
117+
// tag::clauses_load_csv_remote_locations[]
115118
[source, cypher]
116119
----
117120
LOAD CSV FROM 'https://data.neo4j.com/bands/artists.csv' AS row
118121
MERGE (a:Artist {name: row[1], year: toInteger(row[2])})
119122
RETURN a.name, a.year
120123
----
124+
// end::clauses_load_csv_remote_locations[]
121125
122126
.Result
123127
[role="queryresult",options="header,footer",cols="2*<m"]
@@ -705,10 +709,11 @@ person_tmdbId,bio,born,bornIn,died,person_imdbId,name,person_poster,person_url
705709
----
706710
707711
[NOTE]
708-
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.
712+
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.
709713
If you are using an older version of Neo4j, use an xref:subqueries/call-subquery.adoc#importing-with[importing `WITH` clause] instead.
710714
711715
.Query
716+
// tag::clauses_load_csv_transactions[]
712717
[source, cypher]
713718
----
714719
LOAD CSV WITH HEADERS FROM 'https://data.neo4j.com/importing-cypher/persons.csv' AS row
@@ -717,6 +722,7 @@ CALL (row) {
717722
SET p.name = row.name, p.born = row.born
718723
} IN TRANSACTIONS OF 200 ROWS
719724
----
725+
// end::clauses_load_csv_transactions[]
720726
721727
.Result
722728
[source, role="queryresult"]
@@ -751,11 +757,13 @@ A common use case for this function is to generate sequential unique IDs for CSV
751757
----
752758
753759
.Query
760+
// tag::clauses_load_csv_linenumber[]
754761
[source, cypher]
755762
----
756763
LOAD CSV FROM 'file:///artists.csv' AS row
757764
RETURN linenumber() AS number, row
758765
----
766+
// end::clauses_load_csv_linenumber[]
759767
760768
.Result
761769
[role="queryresult",options="header,footer",cols="2*<m"]
@@ -786,11 +794,13 @@ The xref:functions/load-csv.adoc#functions-file[`file()`] function provides the
786794
----
787795
788796
.Query
797+
// tag::clauses_load_csv_file[]
789798
[source, cypher, role=test-result-skip]
790799
----
791800
LOAD CSV FROM 'file:///artists.csv' AS row
792801
RETURN DISTINCT file() AS path
793802
----
803+
// end::clauses_load_csv_file[]
794804
795805
.Result
796806
[role="queryresult",options="header,footer",cols="1*<m"]
@@ -837,6 +847,7 @@ Id,Name,Year
837847
----
838848
839849
.Query
850+
// tag::clauses_load_csv_headers[]
840851
[source, cypher]
841852
----
842853
LOAD CSV WITH HEADERS FROM 'file:///artists-with-headers.csv' AS row
@@ -845,6 +856,7 @@ RETURN
845856
a.name AS name,
846857
a.year AS year
847858
----
859+
// end::clauses_load_csv_headers[]
848860
849861
.Result
850862
[role="queryresult",options="header,footer",cols="2*<m"]
@@ -880,11 +892,13 @@ If you try to import a file that doesn't use `,` as field delimiter and you also
880892
----
881893
882894
.Query
895+
// tag::clauses_load_csv_field_terminator[]
883896
[source, cypher]
884897
----
885898
LOAD CSV FROM 'file:///artists-fieldterminator.csv' AS row FIELDTERMINATOR ';'
886899
MERGE (:Artist {name: row[1], year: toInteger(row[2])})
887900
----
901+
// end::clauses_load_csv_field_terminator[]
888902
889903
.Result
890904
[source, role="queryresult"]

modules/ROOT/pages/clauses/order-by.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ CREATE
4040
`ORDER BY` is used to sort the output.
4141

4242
.Query
43+
// tag::clauses_order_by[]
4344
[source, cypher]
4445
----
4546
MATCH (n)
4647
RETURN n.name, n.age
4748
ORDER BY n.name
4849
----
50+
// end::clauses_order_by[]
4951

5052
The nodes are returned, sorted by their name.
5153

@@ -67,12 +69,14 @@ You can order by multiple properties by stating each variable in the `ORDER BY`
6769
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.
6870

6971
.Query
72+
// tag::clauses_order_by_multiple[]
7073
[source, cypher]
7174
----
7275
MATCH (n)
7376
RETURN n.name, n.age
7477
ORDER BY n.age, n.name
7578
----
79+
// end::clauses_order_by_multiple[]
7680

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

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

247251

248252
.Standalone use of `ORDER BY`
253+
// tag::clauses_order_by_standalone[]
249254
[source, cypher]
250255
----
251256
MATCH (n)
252257
ORDER BY n.name
253258
RETURN collect(n.name) AS names
254259
----
260+
// end::clauses_order_by_standalone[]
255261

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

266272
.`ORDER BY` used in conjunction with `SKIP` and `LIMIT`
273+
// tag::clauses_order_by_descending[]
267274
[source, cypher]
268275
----
269276
MATCH (n)
@@ -272,6 +279,7 @@ SKIP 1
272279
LIMIT 1
273280
RETURN n.name AS name
274281
----
282+
// end::clauses_order_by_descending[]
275283

276284
.Result
277285
[role="queryresult",options="header,footer",cols="1*<m"]

modules/ROOT/pages/clauses/skip.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ d|Rows: 2
6969
The following query returns the middle two rows, with `SKIP` skipping the first and xref:clauses/limit.adoc[`LIMIT`] removing the final two.
7070
7171
.Query
72+
// tag::clauses_skip[]
7273
[source, cypher]
7374
----
7475
MATCH (n)
@@ -77,6 +78,7 @@ ORDER BY n.name
7778
SKIP 1
7879
LIMIT 2
7980
----
81+
// end::clauses_skip[]
8082
8183
.Result
8284
[role="queryresult",options="header,footer",cols="1*<m"]
@@ -126,12 +128,14 @@ d|Rows: 4
126128
`SKIP` can be used as a standalone clause, or in conjunction with xref:clauses/order-by.adoc[`ORDER BY`] or xref:clauses/limit.adoc[`LIMIT`].
127129

128130
.Standalone use of `SKIP`
131+
// tag::clauses_skip_standalone[]
129132
[source, cypher]
130133
----
131134
MATCH (n)
132135
SKIP 2
133136
RETURN collect(n.name) AS names
134137
----
138+
// end::clauses_skip_standalone[]
135139

136140
.Result
137141
[role="queryresult",options="header,footer",cols="1*<m"]
@@ -169,6 +173,7 @@ RETURN collect(n.name) AS names
169173
`OFFSET` was introduced as part of Cypher's xref:appendix/gql-conformance/index.adoc[] and can be used as a synonym to `SKIP`.
170174

171175
.Query
176+
// tag::clauses_skip_offset[]
172177
[source, cypher]
173178
----
174179
MATCH (n)
@@ -177,6 +182,7 @@ OFFSET 2
177182
LIMIT 2
178183
RETURN collect(n.name) AS names
179184
----
185+
// end::clauses_skip_offset[]
180186

181187
.Result
182188
[role="queryresult",options="header,footer",cols="1*<m"]

modules/ROOT/pages/clauses/unwind.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ The `UNWIND` clause requires you to specify a new name for the inner values.
2929
We want to transform the literal list into rows named `x` and return them.
3030

3131
.Query
32+
// tag::clauses_unwind_list[]
3233
[source, cypher]
3334
----
3435
UNWIND [1, 2, 3, null] AS x
3536
RETURN x, 'val' AS y
3637
----
38+
// end::clauses_unwind_list[]
3739

3840
Each value of the original list -- including `null` -- is returned as an individual row.
3941

@@ -109,13 +111,15 @@ The two lists -- _a_ and _b_ -- are concatenated to form a new list, which is th
109111
Multiple `UNWIND` clauses can be chained to unwind nested list elements.
110112

111113
.Query
114+
// tag::clauses_unwind_nested_list[]
112115
[source, cypher]
113116
----
114117
WITH [[1, 2], [3, 4], 5] AS nested
115118
UNWIND nested AS x
116119
UNWIND x AS y
117120
RETURN y
118121
----
122+
// end::clauses_unwind_nested_list[]
119123

120124
The first `UNWIND` results in three rows for `x`, each of which contains an element of the original list (two of which are also lists); namely, `[1, 2]`, `[3, 4]`, and `5`.
121125
The second `UNWIND` then operates on each of these rows in turn, resulting in five rows for `y`.
@@ -212,13 +216,15 @@ Create a number of nodes and relationships from a parameter-list without using `
212216
----
213217

214218
.Query
219+
// tag::clauses_unwind_create_nodes[]
215220
[source, cypher]
216221
----
217222
UNWIND $events AS event
218223
MERGE (y:Year {year: event.year})
219224
MERGE (y)<-[:IN]-(e:Event {id: event.id})
220225
RETURN e.id AS x ORDER BY x
221226
----
227+
// end::clauses_unwind_create_nodes[]
222228

223229
Each value of the original list is unwound and passed through `MERGE` to find or create the nodes and relationships.
224230

0 commit comments

Comments
 (0)