postgresqlapache-age

How to properly write AGE queries with the `RETURN *` Cypher command


I am trying to add support for the following query for an AGE project that converts Cypher queries to SQL:

MATCH p=({name: 'agens-graph'})-[{lang: 'java'}]->(m) RETURN *;

This successfully converts into the following:

SELECT * FROM cypher('test', $$ MATCH p=({name: 'agens-graph'})-[{lang: 'java'}]->(m) RETURN * $$) AS (v agtype);

However, this produces an error:

ERROR:  return row and column definition list do not match

Assuming I do not know the exact columns that will be produced with the RETURN *, is there a way to replace the AS (v agtype) to something else that will support the query (something like AS (* agtype))? Or is this not yet supported in AGE?


Solution

  • As per the documentation of RETURN clause, even if you are using RETURN *, you need to define the number of columns to be returned by the cypher query and so any alike of * agtype is not yet supported. For example:

    SELECT *
    FROM cypher('graph_name', $$
    MATCH (a {name: 'A'})-[r]->(b)
    RETURN *
    $$) as (a agtype, b agtype, r agtype);
    

    Reference: RETURN clause