After reading the documentation i didn't find what the Cypher() function does if NULL arguments are provided. From my understanding if there is a correctly prepared statement it should exectute that. Is that correct? Also on what graph? Because the "graph_name" argument is also NULL in some of those cases.
Asked
Active
Viewed 124 times
1 Answers
2
The cypher function syntax is as follows:
SELECT * FROM cypher('graph_name', $$
/* Cypher Query Here */
$$) AS (result1 agtype, result2 agtype);
So, it is necessary to pass the name of the graph as the first argument and the query as a second argument (note that the query must have the double dollar signs at the beginning and at the end). If these arguments are not passed, an error occurs because the function will not be able to identify the columns and namespace that it is working on. Here are some examples of errors:
-- Inserting nothing
SELECT * FROM cypher() as (a agtype);
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
-- Not inserting the double dollar signs
SELECT * FROM cypher('graph_name') as (a agtype);
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Failed. ^
-- Not passing the query correctly
SELECT * FROM cypher('graph_name', $$$$) as (a agtype);
ERROR: syntax error at end of input
LINE 1: SELECT * FROM cypher('graph_name', $$$$) as (a agtype);
The documentation also states that there are two things that we need to have in consideration:
- 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.
The first point means that, if the query does not return results (e.g. trying to return a property that doesn't belong to a vertex or edge) it still needs to show a table structure when returning the query, even if it is blank one.

Matheus Farias
- 716
- 1
- 10
-
in the regression tests : https://github.com/apache/age/blob/master/regress/sql/analyze.sql at line 47 and 48 cypher function has NULL arguments but still the query in the prepared statement is executed. How does that work? – Panagiotis Foliadis Mar 06 '23 at 18:44