Stored Functions
User-defined Cypher functions with typed parameters, default values, schema namespacing, and body caching. Functions can query the graph and document store.
CREATE FUNCTION
CREATE FUNCTION greet(name: STRING) RETURNS STRING AS {
'Hello, ' + name + '!'
}
-- With default parameter
CREATE FUNCTION greet(name: STRING = 'World') RETURNS STRING AS {
'Hello, ' + name + '!'
}
-- Graph-reading function
CREATE FUNCTION friend_count(person: STRING) RETURNS INT AS {
MATCH (p:Person {name: person})-[:FRIEND]->(f) RETURN count(f)
}
-- Document-reading function
CREATE FUNCTION get_email(username: STRING) RETURNS STRING AS {
MATCH DOCUMENT d IN auth.users WHERE d.username = username RETURN d.email
}
-- Mutating function
CREATE FUNCTION log_event(event: STRING) RETURNS VOID MUTATING AS {
CREATE DOCUMENT IN audit uuid() {event: event, ts: timestamp()}
}Calling Functions
-- Inline in queries
MATCH (n:Person) RETURN greet(n.name)
-- With CALL...YIELD
CALL greet('Alice') YIELD result
-- In WHERE clauses
MATCH (n:Person) WHERE friend_count(n.name) > 5 RETURN n.nameManagement
CREATE OR REPLACE FUNCTION greet(...) ... DROP FUNCTION greet SHOW FUNCTIONS SHOW FUNCTIONS IN auth
Parameter Types
| Type | Description |
|---|---|
| STRING | Text value |
| INT / INTEGER | 64-bit integer |
| FLOAT / DOUBLE | 64-bit float |
| BOOL / BOOLEAN | Boolean |
| LIST | Array |
| MAP | Key-value object |
| ANY | Any type |
| VOID | No return (mutating only) |
Schema namespacing: auth.* functions are protected (admin only). Max nesting depth: 16 levels with cycle detection.