5.1.1 Graph Element Variables

Vertex and edge pattern variables ranges over vertices and edges respectively.

For example, consider the following graph pattern which contains three graph element variables.

(v1)–[e]->(v2)

In the preceding graph pattern, v1 and v2 are two vertex pattern variables and e is an edge pattern variable.

Ensure that you apply the following rules for the graph pattern variables:

  • You cannot use the same variable name for both a vertex and an edge.
  • You can use the same variable name in two different vertex patterns as shown:

    MATCH (a IS person) -> (a IS person)

    In the preceding example, the vertex variable a is used in two vertex patterns - (a IS person) and (a IS person). This implies that the two vertex patterns that declare the same vertex variable must bind to the same vertex. Thus the vertex variable binds to a unique vertex but the vertex pattern can appear multiple times in the same graph pattern.

  • You can use the same variable name in two different edge patterns.
  • Anonymous (that is, omitted) vertex and edge variables are supported. See Example 5-8.