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

Cypher()

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

Syntax cypher(graph_name, query_string, parameters)

Returns

  1. A SETOF records

Arguments:

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.

Considerations:

  • 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.

Query:

  1. SELECT * FROM cypher('graph_name', $$
  2. /* Cypher Query Here */
  3. $$) 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

SELECT Clause

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:

  1. SELECT
  2. cypher('graph_name', $$
  3. MATCH (v:Person)
  4. RETURN v.name
  5. $$);
  1. ERROR: cypher(...) in expressions is not supported
  2. LINE 3: cypher('graph_name', $$
  3. ^
  4. HINT: Use subquery instead if possible.