FOR

The FOR clause makes it possible to transform any list back into individual rows. The list can be a parameter that is passed in, a previously collected result, or any other list expression.

FOR is the GQL conformant synonym of UNWIND. FOR is valid wherever UNWIND is valid and has the same semantics. FOR and UNWIND differ only in syntax.

FOR variable IN expression

For comparison, the Cypher® UNWIND form is:

UNWIND expression AS variable

Neo4j does not guarantee the row order produced by FOR. The only clause that guarantees a specific row order is ORDER BY.

Unwinding a list

We want to transform the literal list into rows named x and return them.

Query
FOR x IN [1, 2, 3, null]
RETURN x, 'val' AS y

Each value of the original list — including null — is returned as an individual row. The same outcome is shown here using the equivalent UNWIND form:

UNWIND [1, 2, 3, null] AS x
RETURN x, 'val' AS y
Result
x y

1

"val"

2

"val"

3

"val"

<null>

"val"

Rows: 4

Further behavior

All cases described for UNWIND apply to FOR: empty lists, nested lists, expressions that are not lists, parameters, and combinations with WITH, RETURN, subqueries, and so on.