Book Image

Learning Cypher

By : Onofrio Panzarino
Book Image

Learning Cypher

By: Onofrio Panzarino

Overview of this book

Table of Contents (13 chapters)

Loops


Due to the nature of the Cypher queries, usually, you won't need something like a loop used in other programming languages. In fact, as you have probably already realized, the general structure of a Cypher query is formed by three phases and each one of these is optional. The phases are as follows:

  • Read: This is the phase where you read data from the graph using the START, MATCH, or OPTIONAL MATCH clauses.

  • Write: This is the phase where you modify the graph using CREATE, MERGE, SET, and all the other clauses we learned in this chapter.

  • Return: This is the phase where you choose what to return to the caller by using the RETURN clause. This part can be replaced by a WITH clause and then the query can start again from the read phase.

The read phase is important because the write phase will be executed for every item found in the read phase. For example, consider the following query:

MATCH (a:User {surname: "Roe"})
SET a.place = "London"
RETURN a

In this query, the SET command will be executed...