Using the TEMP variable
GQL allows the use of TEMP to declare temporary variables within a graph pattern. The temporary variables are discarded once the MATCH statement concludes.
Take the following example:
GQL:
MATCH (TEMP c:Category WHERE c.name = "Graph")-[]->(g:Lang)
RETURN g.name
In this query, a temporary variable, c, and a general variable, g, are declared in the MATCH statement. The c.name is used to filter the Graph category in the WHERE clause, which is part of the MATCH statement.
Attempting to use the c variable in the subsequent statements will result in an exception:
GQL:
MATCH (TEMP c:Category)-[]->(g:Lang)
FILTER c.name = "Graph"
RETURN g.name
The query will raise an exception because the temporary variable, c, is removed after the execution of the MATCH statement.