Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tags for clause section #1138

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion modules/ROOT/pages/clauses/finish.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,30 @@
[[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`:

.Query
// tag::clauses_finish_create[]
[source, cypher]
----
CREATE (p:Person)
FINISH
----
// end::clauses_finish_create[]

It is equivalent to the following query:

Expand Down
2 changes: 2 additions & 0 deletions modules/ROOT/pages/clauses/foreach.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ CREATE
This query will set the property `marked` to `true` on all nodes along a path.

.Query
// tag::clauses_foreach[]
[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[]

.Result
[role="queryresult",options="footer",cols="1*<m"]
Expand Down
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 @@ -700,10 +704,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 @@ -712,6 +717,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 @@ -746,11 +752,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 @@ -781,11 +789,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 @@ -832,6 +842,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 @@ -840,6 +851,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 @@ -875,11 +887,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
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
6 changes: 6 additions & 0 deletions modules/ROOT/pages/clauses/skip.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -77,6 +78,7 @@ ORDER BY n.name
SKIP 1
LIMIT 2
----
// end::clauses_skip[]

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
Expand Down Expand Up @@ -126,12 +128,14 @@ d|Rows: 4
`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`].

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

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

.Query
// tag::clauses_skip_offset[]
[source, cypher]
----
MATCH (n)
Expand All @@ -177,6 +182,7 @@ OFFSET 2
LIMIT 2
RETURN collect(n.name) AS names
----
// end::clauses_skip_offset[]

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
Expand Down
6 changes: 6 additions & 0 deletions modules/ROOT/pages/clauses/unwind.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ The `UNWIND` clause requires you to specify a new name for the inner values.
We want to transform the literal list into rows named `x` and return them.

.Query
// tag::clauses_unwind_list[]
[source, cypher]
----
UNWIND [1, 2, 3, null] AS x
RETURN x, 'val' AS y
----
// end::clauses_unwind_list[]

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

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

.Query
// tag::clauses_unwind_nested_list[]
[source, cypher]
----
WITH [[1, 2], [3, 4], 5] AS nested
UNWIND nested AS x
UNWIND x AS y
RETURN y
----
// end::clauses_unwind_nested_list[]

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`.
The second `UNWIND` then operates on each of these rows in turn, resulting in five rows for `y`.
Expand Down Expand Up @@ -212,13 +216,15 @@ Create a number of nodes and relationships from a parameter-list without using `
----

.Query
// tag::clauses_unwind_create_nodes[]
[source, cypher]
----
UNWIND $events AS event
MERGE (y:Year {year: event.year})
MERGE (y)<-[:IN]-(e:Event {id: event.id})
RETURN e.id AS x ORDER BY x
----
// end::clauses_unwind_create_nodes[]

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

Expand Down
6 changes: 5 additions & 1 deletion modules/ROOT/pages/clauses/use.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,30 @@ CREATE ALIAS `myComposite`.`myConstituent` FOR DATABASE `myDatabase`;
[[query-use-examples-query-graph]]
=== Query a graph

In this example it is assumed that the DBMS contains a database named `myDatabase`:
This example assumes that the DBMS contains a database named `myDatabase`:

.Query
// tag::clauses_use[]
[source, cypher]
----
USE myDatabase
MATCH (n) RETURN n
----
// end::clauses_use[]

[[query-use-examples-query-composite-database-constituent-graph]]
=== Query a composite database constituent graph

In this example it is assumed that the DBMS contains a composite database named `myComposite`, which includes an alias named `myConstituent`:

.Query
// tag::clauses_use_composite[]
[source, cypher]
----
USE myComposite.myConstituent
MATCH (n) RETURN n
----
// end::clauses_use_composite[]


[[query-use-examples-query-composite-database-constituent-graph-dynamically]]
Expand Down
Loading