Search code examples
postgresqlapache-age

How do I return multiple columns with the RETURN keyword with a cypher query in apache age


In the following code, it's a simple query that fetches nodes that has the specified relation

test=# SELECT *
FROM cypher('first_graph', $$
MATCH (a:Person)-[]->(b:Person) RETURN a.name, b.name
$$) as (v agtype);

When I ran the query I get the following error

ERROR:  return row and column definition list do not match
LINE 2: FROM cypher('first_graph', $$..
             ^

Solution

  • When you are returning more than 1 columns from cypher query, you need to specify exact number of columns outside the query.

    test=# SELECT *
    FROM cypher('first_graph', $$
    MATCH (a:Person)-[]->(b:Person) RETURN a.name, b.name
    $$) as (v agtype, w agtype);
    

    The above query will work fine.