UltipaDocs
Products
Solutions
Resources
Company
Start Free Trial
UltipaDocs
Start Free Trial
  • Introduction
  • GQL vs Other Languages
    • Overview
    • Node and Edge Patterns
    • Path Patterns
    • Quantified Paths
    • Questioned Paths
    • Shortest Paths
    • Cheapest Paths
    • K-Hop Traversal
    • Graph Patterns
    • Overview
    • Open Graphs
    • Closed Graphs
    • Graph Types
    • Constraints
    • Projections
    • Storage Maintenance
    • Node and Edge IDs
    • INSERT
    • INSERT OVERWRITE
    • UPSERT
    • MERGE
    • SET
    • REMOVE
    • DELETE
    • FOREACH
    • Query Composition
    • Result Table and Visualization
    • MATCH
    • OPTIONAL MATCH
    • FILTER
    • LET
    • FOR
    • ORDER BY
    • LIMIT
    • SKIP
    • CALL
    • RETURN
    • Composite Query
    • NEXT
    • All Functions
    • Element Functions
    • Path Functions
    • Aggregate Functions
    • Mathematical Functions
    • Trigonometric Functions
    • String Functions
    • List Functions
    • Datetime Functions
    • Spatial Functions
    • Null Functions
    • Utility Functions
    • Type Conversion Functions
    • Table Functions
    • Database Functions
  • Operators
  • Predicates
    • CASE
    • LET Value Expression
    • Value Query Expression
    • List Expressions
    • Index
    • Full-text Index
    • Vector Index
  • Transactions
  • Triggers
  • Query Management
  • Execution Plan
  • Backup and Restore
    • Variables
    • Values and Types
    • Comments
    • Reserved Words
    • Naming Conventions
    • 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.

Query Parameters

A query parameter is a placeholder of the form $name that is bound to a value supplied by the driver at execution time, rather than written as a literal in the query text. Parameters can be referenced anywhere a value expression is allowed.

GQL
MATCH (p:Person)
WHERE p.age > $minAge AND p.city = $city
RETURN p.name

Parameter values are not declared inside the query; they are passed in through the driver's parameter map. Using parameters instead of string-concatenated literals avoids injection risks, keeps the query text reusable across different inputs, and lets the planner reuse cached plans.