The AGE Cypher Query Format

Cypher queries are constructed using a function called cypher in ag_catalog which returns a Postgres SETOF records.


Cypher() executes the cypher query passed as an argument.

Syntax cypher(graph_name, query_string, parameters)


A SETOF records


Argument Name Description
graph_name The target graph for the Cypher query.
query_string The Cypher query to be executed.
parameters An optional map of parameters used for Prepared Statements. Default is NULL.


  • If a Cypher query does not return results, a record definition still needs to be defined.

  • The parameter map can only be used with Prepared Statements. An error will be thrown otherwise.


SELECT * FROM cypher('graph_name', $$ 
/* Cypher Query Here */ 
$$) AS (result1 agtype, result2 agtype);

Cypher in an Expression

Cypher may not be used as part of an expression, use a subquery instead. See Advanced Cypher Queries for information about how to use Cypher queries with Expressions


Calling Cypher in the SELECT clause as an independent column is not allowed. However Cypher may be used when it belongs as a conditional.

Not Allowed:

    cypher('graph_name', $$
         MATCH (v:Person)
ERROR:  cypher(...) in expressions is not supported
LINE 3: 	cypher('graph_name', $$
HINT:  Use subquery instead if possible.