Variables¶
In GQL, a variable is an identifier assigned to a collection of values of a specific data type. Variables can be used to hold values for data retrieval and manipulation within procedures.
Categories of variables by role in pattern matching¶
- Node variable: Represents nodes in the graph. For more information, see Node patterns.
- Edge variable: Represents edges in the graph. For more information, see Edge patterns.
- Path variable: Represents paths in the graph. For more information, see Path patterns.
Categories of variables by declaration types¶
- Primitive value variable: Stores and manipulates values. For more information, see Primitive value variables.
- Aggregator value variable: Stores and aggregates values. For more information, see Aggregator value variables.
- Active set variable: Stores the set of nodes to be processed. For more information, see Active set variables.
- Graph variable: Stores and manipulates subgraphs. For more information, see Graph variables.
- Table variable: Stores and manipulates tabular data. For more information, see Table variables.
- File variable: Defines file-based data sources and destinations. For more information, see File variables.
Variable scopes¶
In GQL, curly brackets ({}) are used to create blocks in procedures. Blocks can be nested within each other, allowing for structured control flow and variable management.
Variables can have two types of scopes depending on the block in which they are declared:
- Block scoping
- Global scoping
Block scoping¶
A block-scoped variable is declared inside a nested block and can only be accessed within that block.
Note
A block-scoped variable cannot have duplicate names as variables already declared in the outer block.
Only primitive value variables support block scoping.
Global scoping¶
A global-scoped variable must be declared at the global scope, that is, at the top level of a procedure body, outside of any nested blocks.
The following types of variables support global scoping:
- Primitive value variables
- Aggregator value variables, including global aggregator value variables and node-attached aggregator value variables
- Active set variables
- Graph variables
- Table variables
- File variables
After declaration, node-attached aggregator value variables can be accessed for aggregation operations only within per_block clauses in match compute statements, whereas all other global-scoped variables can be accessed from any part of the procedure.