@@ -63,7 +63,7 @@ RETURN person.name as name,
6363 MATCH (person)-[r:HAS_DOG]->(dog:Dog)
6464 WHERE r.since > 2017
6565 RETURN dog.name
66- } as youngDogs
66+ } AS youngDogs
6767----
6868
6969[role="queryresult",options="header,footer",cols="2*<m"]
@@ -120,15 +120,14 @@ The below example shows the collection of pet names each person has by using a `
120120[source, cypher]
121121----
122122MATCH (person:Person)
123- RETURN
124- person.name AS name,
125- COLLECT {
126- MATCH (person)-[:HAS_DOG]->(dog:Dog)
127- RETURN dog.name AS petName
128- UNION
129- MATCH (person)-[:HAS_CAT]->(cat:Cat)
130- RETURN cat.name AS petName
131- } AS petNames
123+ RETURN person.name AS name,
124+ COLLECT {
125+ MATCH (person)-[:HAS_DOG]->(dog:Dog)
126+ RETURN dog.name AS petName
127+ UNION
128+ MATCH (person)-[:HAS_CAT]->(cat:Cat)
129+ RETURN cat.name AS petName
130+ } AS petNames
132131----
133132
134133[role="queryresult",options="header,footer",cols="2*<m"]
@@ -154,10 +153,10 @@ In the example below, the outer variable `name` is shadowed and will therefore t
154153WITH 'Peter' as name
155154MATCH (person:Person {name: name})
156155RETURN COLLECT {
157- WITH 'Ozzy' AS name
158- MATCH (person)-[r:HAS_DOG]->(d:Dog {name: name})
159- RETURN d.name
160- } as dogsOfTheYear
156+ WITH 'Ozzy' AS name
157+ MATCH (person)-[r:HAS_DOG]->(d:Dog {name: name})
158+ RETURN d.name
159+ } AS dogsOfTheYear
161160----
162161
163162.Error message
@@ -173,12 +172,13 @@ Note that the outer scope variable `person` referenced in the main query is stil
173172[source, cypher]
174173----
175174MATCH (person:Person)
176- RETURN person.name AS name, COLLECT {
177- WITH 2018 AS yearOfTheDog
178- MATCH (person)-[r:HAS_DOG]->(d:Dog)
179- WHERE r.since = yearOfTheDog
180- RETURN d.name
181- } as dogsOfTheYear
175+ RETURN person.name AS name,
176+ COLLECT {
177+ WITH 2018 AS yearOfTheDog
178+ MATCH (person)-[r:HAS_DOG]->(d:Dog)
179+ WHERE r.since = yearOfTheDog
180+ RETURN d.name
181+ } AS dogsOfTheYear
182182----
183183
184184[role="queryresult",options="header,footer",cols="2*<m"]
@@ -206,10 +206,10 @@ See a few examples below of how `COLLECT` can be used in different positions wit
206206MATCH (person:Person)
207207RETURN person.name,
208208 COLLECT {
209- MATCH (person)-[:HAS_DOG]->(d:Dog)
210- MATCH (d)-[:HAS_TOY]->(t:Toy)
211- RETURN t.name
212- } as toyNames
209+ MATCH (person)-[:HAS_DOG]->(d:Dog)
210+ MATCH (d)-[:HAS_TOY]->(t:Toy)
211+ RETURN t.name
212+ } AS toyNames
213213----
214214
215215[role="queryresult",options="header,footer",cols="2*<m"]
@@ -230,7 +230,7 @@ RETURN person.name,
230230MATCH (person:Person)
231231 WHERE person.name = "Peter"
232232SET person.dogNames = COLLECT { MATCH (person)-[:HAS_DOG]->(d:Dog) RETURN d.name }
233- RETURN person.dogNames as dogNames
233+ RETURN person.dogNames AS dogNames
234234----
235235
236236[role="queryresult",options="header,footer",cols="1*<m"]
@@ -274,9 +274,10 @@ and then calculates the average age for each group.
274274[source, cypher]
275275----
276276MATCH (person:Person)
277- RETURN COLLECT { MATCH (person)-[:HAS_DOG]->(d:Dog)
278- RETURN d.name } AS dogNames,
279- avg(person.age) AS averageAge
277+ RETURN COLLECT {
278+ MATCH (person)-[:HAS_DOG]->(d:Dog)
279+ RETURN d.name } AS dogNames,
280+ avg(person.age) AS averageAge
280281 ORDER BY dogNames
281282----
282283
0 commit comments