UNWIND

The UNWIND clause transforms a list into individual rows, creating one row for each element in the list.

Behavior

  • Each element in the list becomes a separate row
  • The order of rows preserves the original list order
  • Useful for processing lists, creating multiple entities, or parameter expansion

Basic Example

Create a node with an array property:

GRAPH.QUERY DEMO_GRAPH "CREATE (p {array:[1,2,3]})"

Unwind the array into individual rows:

GRAPH.QUERY DEMO_GRAPH "MATCH (p) UNWIND p.array AS y RETURN y"

Result:

y
1
2
3

Practical Examples

Create Multiple Nodes from a List

GRAPH.QUERY DEMO_GRAPH
"UNWIND ['Alice', 'Bob', 'Charlie'] AS name
CREATE (:Person {name: name})"

Process Nested Data

GRAPH.QUERY DEMO_GRAPH
"WITH [{name: 'Alice', age: 30}, {name: 'Bob', age: 25}] AS people
UNWIND people AS person
CREATE (:Person {name: person.name, age: person.age})"

Combine with Other Clauses

GRAPH.QUERY DEMO_GRAPH
"MATCH (p:Person)
WITH collect(p.name) AS names
UNWIND names AS name
RETURN name ORDER BY name"
Frequently Asked Questions 4
What does UNWIND do?

UNWIND transforms a list into individual rows, creating one row per element. It is the inverse of the collect() aggregation function.

Can I UNWIND a literal list?

Yes. You can unwind inline lists directly: UNWIND ['Alice', 'Bob'] AS name CREATE (:Person {name: name}). This is useful for batch operations.

What happens if I UNWIND an empty list?

If the list is empty, UNWIND produces zero rows, effectively eliminating that record from the result stream. No subsequent clauses will execute for that record.

Can I UNWIND nested lists or maps?

Yes. You can unwind lists of maps and access their properties: UNWIND [{name: 'Alice'}, {name: 'Bob'}] AS person CREATE (:Person {name: person.name}).