All Products
Search
Document Center

PolarDB:Cypher query format

Last Updated:Jan 06, 2025

Cypher queries are constructed by using the cypher function in ag_catalog which returns a SETOF record.

Cypher()

The cypher() function executes the Cypher query that is passed in.

Syntax

cypher(graph_name, query_string, parameters)

Parameter description

Parameter 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 for prepared statements. Default value: NULL.

Note
  • A record definition must be defined even if the Cypher query does not return results.

Return value

The function returns a set of records.

Example

SELECT * FROM cypher('graph_name', $$
/* Write Cypher query here */
$$) AS (result1 agtype, result2 agtype);
Note

$$ can be used within the Cypher function in the following format:

SELECT * FROM cypher('graph_name', $my_cypher$
/* Specify the Cypher query that contains $$ here */
$my_cypher$) AS (result1 agtype, result2 agtype);

Using Cypher in an expression

Cypher cannot be be used as part of an expression. Use a subquery instead.

SELECT clause

You cannot call Cypher as an independent column in the SELECT clause. However, Cypher can be used as a part of the conditions.

You cannot perform the following operation:

SELECT
    cypher('graph_name', $$
         MATCH (v:Person)
         RETURN v.name
     $$);

Sample result:

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