Skip to content
Developer Edition runs on one host and does not require a product license file. Need multi-host deployment or performance testing at scale? Explore Enterprise Edition

CALL inline procedures

To perform more complex queries and result processing in GQL, you can use the CALL statement to encapsulate a set of statements into a statement block. You can then further operate on the results of this block, such as sorting, limiting, and aggregating. This is similar to enclosing a subexpression in parentheses in an expression to ensure that its result can be referenced and processed. Such statement blocks are known as inline procedures. Use CALL to run an inline procedure.

For information about how to call named procedures, see CALL named procedures.

Syntax

call_inline_procedure_statement
OPTIONAL CALL { procedure_body }

call_inline_procedure_statement ::=
    'OPTIONAL'? 'CALL' '{' procedure_body '}' 

Parameters

OPTIONAL

When the keyword OPTIONAL is used, the query returns null as the result even if the inline procedure does not find a match. The query continues to return data that may match other queries. Otherwise, the query returns no results if the inline procedure does not find a match.

procedure_body

The processing logic of the procedure. It can consist of primitive value variable definitions and statements of the following types:

Examples

The following examples are based on the example dataset.

Perform calculations in an inline procedure

'''
LET x = 10 
LET y = 20 
CALL { 
    LET z = 30 
    RETURN x + y AS sum_xy, z * 2 AS double_z } 
RETURN *
'''

Return:

+----------+--------+----+----+
| double_z | sum_xy | x  | y  |
+----------+--------+----+----+
| 60       | 30     | 10 | 20 |
+----------+--------+----+----+

Perform queries in an inline procedure

'''
USE movie 
CALL {  
       MATCH (v@Director) RETURN v 
       UNION 
       MATCH (v@`User`) RETURN v } 
LIMIT 3 
RETURN v.name AS name, v.id AS id 
ORDER BY id 
'''

Return:

+----------------------+------+
| name                 | id   |
+----------------------+------+
| Krzysztof Kieślowski | 1126 |
| William Shatner      | 1748 |
| Roberto Rossellini   | 4410 |
+----------------------+------+

Perform queries in an optional inline procedure

'''
USE movie 
LET a = 1 
LET b = 2 
OPTIONAL CALL { 
                MATCH (v:Movie{id:1}) 
                RETURN v.id AS id } 
RETURN *
'''

Return:

+---+---+----+
| a | b | id |
+---+---+----+
| 1 | 2 | 1  |
+---+---+----+

Implement a loop in an inline procedure

'''
VALUE a = 2
CALL {
  WHILE a > 0 THEN {
  SET a = a - 1
  LOG_INFO(a)
  }
  RETURN a AS b
  }
  RETURN b
'''

Return:

+---+
| b |
+---+
| 0 |
+---+
Log:
2026-01-13T02:02:07.693285 INFO  - 1
2026-01-13T02:02:07.693597 INFO  - 0

Perform match compute in an inline procedure

The following example assumes that the temporary graph #movie_temporary_graph is created and populated with data from the example dataset movie. For how to create a temporary graph, see CREATE TEMPORARY GRAPH statement.

'''
USE #movie_temporary_graph
CALL {
  MATCH (a) WHERE a.id IN [1,2,3]
  PER NODE (a) {
    LOG_INFO(a.name)
  }
}
'''

Return:

Log:
2026-03-23T09:40:51.202952 INFO  - Cowboy Bebop
2026-03-23T09:40:51.202952 INFO  - Shadows in Paradise
2026-03-23T09:40:51.202992 INFO  - George Lucas
2026-03-23T09:40:51.203017 INFO  - Mark Hamill
2026-03-23T09:40:51.203017 INFO  - Harrison Ford

Call nested inline procedures

'''
VALUE a = 1
CALL {
  VALUE b = a + 1
  CALL {
    WHILE b > 0 THEN {
    SET b = b - 1
    LOG_INFO(b)
    }
    RETURN b AS c
  }
RETURN c AS d
}
RETURN d
'''

Return:

+---+
| d |
+---+
| 0 |
+---+
Log:
2026-01-13T02:01:00.221667 INFO  - 1
2026-01-13T02:01:00.222015 INFO  - 0