Skip to content

FOR and list expansion

FOR item IN list produces one row per list element for each incoming row, in list order. Empty and null lists produce zero rows. A null entry in a nonempty list produces a row containing null. Property lookup on an element reference does not regroup those rows.

FOR name IN ['Alice', 'Bob', 'Cara'] WITH ORDINALITY position
RETURN position, name ORDER BY position;

WITH ORDINALITY counts from 1; WITH OFFSET counts from 0. Positions restart for each incoming row.

FOR value IN [10, NULL, 30] WITH OFFSET position
RETURN position, value ORDER BY position;

Supported lists include homogeneous scalar lists, compatible numeric lists, nested lists and lists of graph references produced by paths or collection. Arbitrary heterogeneous union-valued lists are not represented by the query engine.

See list values and ELEMENTS.