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.
To show all procedures in the current graph:
GQLSHOW PROCEDURE
To show a specific procedure:
GQLSHOW PROCEDURE find_friends
Each procedure provides the following metadata:
| Field | Description |
|---|---|
name | The name of the procedure. |
parameters | The parameter definitions. |
returns | The return column definitions. |
comment | The description of the procedure. |
body | The GQL query body. |
creator | The user who created the procedure. |
create_time | The time when the procedure was created. |
GQLCREATE PROCEDURE <procedureName> (<parameterList>) [RETURNS (<returnList>)] [COMMENT '<description>'] AS '<gqlBody>'
Rules:
$paramName TYPE format; the $ prefix is required.STRING, INT, INT32, INT64, UINT64, FLOAT, DOUBLE, BOOL, DATETIME.RETURNS clause is optional and declares output column names and types.COMMENT clause is optional.AS body must be a valid GQL query string containing $param placeholders.CREATE GRAPH, DROP PROCEDURE).To create a procedure that finds friends within N hops:
GQLCREATE 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:
GQLCREATE PROCEDURE count_all_persons () AS 'MATCH (n:Person) RETURN count(n) AS total'
To call a stored procedure directly:
GQLCALL find_friends('U001', 30)
To call a stored procedure within a larger query pipeline:
GQLMATCH (n:Person) CALL find_friends(n._id, 30) YIELD friend_name RETURN n.name, friend_name LIMIT 100
In an embedded CALL:
YIELD clause selects which return columns to project.WHERE conditions on yielded columns are supported.GQLMATCH (n:Person) CALL find_friends(n._id, 20) YIELD friend_name, friend_age WHERE friend_age > 25 RETURN n.name, friend_name, friend_age
To drop a procedure:
GQLDROP PROCEDURE find_friends
To drop a procedure only if it exists:
GQLDROP PROCEDURE IF EXISTS find_friends
NOTEDropping a graph will also remove all procedures associated with that graph.