toList
Generic Description
Wraps a scalar in a one-element list and leaves lists as lists. It is documented separately because explicit type boundaries prevent planner tools from inventing hidden coercions for document-style values.
Simple example:
RETURN toList('incident') AS value
Consumer-Level Explanation
Use it when downstream list logic should accept both scalar and list-shaped inputs without hidden client-side branching. Prefer this function when the input shape is mixed or imported and the query must state the intended type before comparison or aggregation.
More Detailed Explanation
toList makes value shape explicit in Cypher. It is most useful around ingestion, document payloads, and assistant-generated queries where the planner should see the intended type boundary rather than relying on hidden client conversion.
Advanced Example
This example applies toList at the point where a semi-structured value enters typed query logic, making the conversion boundary explicit.
MATCH (d:Document)
WITH d, toList(properties(d.metadata).kind) AS kinds
RETURN d.title AS title, kinds, size(kinds) AS kind_count
ORDER BY title
Real Use Cases
- normalizing imported CSV or document fields before comparison
- guarding mixed payloads before list, map, or numeric operations
- making assistant-authored query contracts explicit and reviewable
Real Limitations And Tradeoffs
- conversion only works when the input can be interpreted unambiguously
- heavy conversion inside analytical queries can hide ingestion contract problems
- type checks describe runtime values, not full schema validation