UltipaDocs
Try Playground
  • Introduction
  • GQL vs Other Languages
    • Overview
    • Node and Edge Patterns
    • Path Patterns
    • Quantified Paths
    • Shortest Paths
    • Graph Patterns
    • Overview
    • Closed Graph
    • Open Graph
    • Graph Sharding and Storage
    • Constraints
    • Unique Identifiers
    • INSERT
    • INSERT OVERWRITE
    • UPSERT
    • SET
    • REMOVE
    • DELETE
    • Query Composition
    • Result Table and Visualization
    • MATCH
    • OPTIONAL MATCH
    • FILTER
    • LET
    • FOR
    • ORDER BY
    • LIMIT
    • SKIP
    • CALL
    • RETURN
    • Composite Query
    • NEXT
    • All Functions
    • Scalar Functions
    • Path Functions
    • Aggregate Functions
    • Mathematical Functions
    • Trigonometric Functions
    • String Functions
    • List Functions
    • Datetime Functions
    • Spatial Functions
    • Type Conversion Functions
    • Table Functions
    • AI & Vector Functions
    • Database Functions
  • Operators
  • Predicates
  • Expressions
    • Index
    • Full-text Index
    • Vector Index
  • Transactions
  • Triggers
  • Query Management
    • Variables
    • Values and Types
    • Comments
    • Reserved Words
    • Syntactic Notation
  • GQL Conformance
  1. Docs
  2. /
  3. ISO GQL
  4. /
  5. Syntax

Variables

A variable is a unique name (identifier) assigned to represent a collection of records. Variables allow users to reference these data throughout a query, enabling data retrieval, manipulation, and further operations.

Graph Pattern Variables

Graph pattern variables include:

  • Element Variable: Includes Node Variable and Edge Variable.
  • Path Variable

These variables can be declared at specific places within path patterns, allowing them to be bound to nodes, edges, or paths that match the pattern.

In this query, n is a node variable bound to a list of nodes, e is an edge variable bound to a list of edges, p is a path variable that holds a path binding:

GQL
MATCH p = (:User {_id: "U01"})<-[e:Follows]-(n:User)
RETURN n, e, p

LET Variable Definition

The LET statement allows you to define variables which effectively adds columns to the intermediate result table.

GQL
LET i = 2
RETURN i + 1

Unreferenced Variables

It is generally a good practice to remove any unreferenced variables from the query. For example,

GQL
MATCH (a)-[e]->(b)
RETURN e

If you don't need to reference the nodes bound to a and b, you can rewrite the query as:

GQL
MATCH ()-[e]->()
RETURN e

Unreferenced variables do not cause syntax errors but can lead to inefficiencies and reduced readability. It is best to avoid declaring variables you do not intend to use.