UltipaDocs
Products
Solutions
Resources
Company
Start Free Trial
UltipaDocs
Start Free Trial
  • Introduction
    • Overview
    • Node and Edge Patterns
    • Path Patterns
    • Quantified Paths
    • Shortest Paths
    • Graph Patterns
    • Overview
    • Typed 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
    • Label Functions
    • Record Functions
    • Table Functions
  • Operators
  • Predicates
    • CASE
    • NULLIF
    • COALESCE
    • LET Value Expression
    • Value Query Expression
    • Index
    • Full-text Index
    • Vector Index
    • Spatial Index
    • Overview
    • Managing HDC Graphs
    • HDC Graph Queries
  • Transaction
  • Trigger
  • Stored Procedure
    • Process
    • Session
    • Job
    • Execution Plan
    • Variables
    • Values and Types
    • Comments
    • Reserved Words
    • Syntactic Notation
  • Access Control
  • GQL Conformance
  1. Docs
  2. /
  3. ISO GQL

Stored Procedures

Overview

A stored procedure is a named, reusable, parameterized GQL query template. Stored procedures are graph-scoped — each procedure belongs to a specific graph. They are stored in the meta-server and callable via the CALL statement.

Stored procedures allow you to encapsulate complex queries into reusable units, making it easier to maintain and share query logic across applications.

Showing Procedures

To show all procedures in the current graph:

GQL
SHOW PROCEDURE

To show a specific procedure:

GQL
SHOW PROCEDURE find_friends

Each procedure provides the following metadata:

FieldDescription
nameThe name of the procedure.
parametersThe parameter definitions.
returnsThe return column definitions.
commentThe description of the procedure.
bodyThe GQL query body.
creatorThe user who created the procedure.
create_timeThe time when the procedure was created.

Creating Procedure

Syntax

GQL
CREATE PROCEDURE <procedureName> (<parameterList>)
  [RETURNS (<returnList>)]
  [COMMENT '<description>']
  AS '<gqlBody>'

Rules:

  • Parameters use the $paramName TYPE format; the $ prefix is required.
  • Supported parameter types: STRING, INT, INT32, INT64, UINT64, FLOAT, DOUBLE, BOOL, DATETIME.
  • The RETURNS clause is optional and declares output column names and types.
  • The COMMENT clause is optional.
  • The AS body must be a valid GQL query string containing $param placeholders.
  • The body must not contain DDL statements (e.g., CREATE GRAPH, DROP PROCEDURE).
  • The procedure name can be up to 128 characters.

Examples

To create a procedure that finds friends within N hops:

GQL
CREATE PROCEDURE find_friends ($userId STRING, $maxDepth INT)
  RETURNS (friend_name STRING, friend_age INT)
  COMMENT 'Find friends within N hops'
  AS 'MATCH (n {_id: $userId})-[:Knows]->(m:Person) WHERE m.age > $maxDepth
      RETURN m.name AS friend_name, m.age AS friend_age'

To create a procedure with no parameters:

GQL
CREATE PROCEDURE count_all_persons ()
  AS 'MATCH (n:Person) RETURN count(n) AS total'

Calling Procedure

Standalone CALL

To call a stored procedure directly:

GQL
CALL find_friends('U001', 30)

Embedded CALL

To call a stored procedure within a larger query pipeline:

GQL
MATCH (n:Person)
CALL find_friends(n._id, 30) YIELD friend_name
RETURN n.name, friend_name
LIMIT 100

In an embedded CALL:

  • Each row from the outer query provides arguments to the procedure.
  • The YIELD clause selects which return columns to project.
  • WHERE conditions on yielded columns are supported.

Example with YIELD and WHERE

GQL
MATCH (n:Person)
CALL find_friends(n._id, 20) YIELD friend_name, friend_age
  WHERE friend_age > 25
RETURN n.name, friend_name, friend_age

Dropping Procedure

To drop a procedure:

GQL
DROP PROCEDURE find_friends

To drop a procedure only if it exists:

GQL
DROP PROCEDURE IF EXISTS find_friends
NOTE

Dropping a graph will also remove all procedures associated with that graph.

Limitations

  • The procedure body must be declarative GQL only — no procedural logic (IF/ELSE, WHILE, variable assignment).
  • A procedure body cannot call another stored procedure (no nesting).
  • Procedure calls execute as independent queries (not transaction-aware).