Search code examples
postgresqlapache-age

Is there a way to query for vertices and edges in a single column in AGE?


Suppose that I want all vertices and edges (and paths) to be listed in a single column, ordered by their type, is it a possibility?

The documentation does not say anything about that even though it does mention edge, path, vertex, map in orderability?

What could be a possible query to achieve this?

EDIT: This is somewhat of an output I am looking for

Image

It clearly displays the orderability between Path, edge, and vertex, however, this only works because they are stored in the form of a property of different vertices.

Is it possible to query for all paths, vertices, edges like this in a single column?


Solution

  • To get the vertices, edge in a single column you can try something like:

    SELECT * FROM cypher('graph', $$
    MATCH (n)-[e]->(m)
    RETURN [n, e, m]
    $$) AS (result agtype);
    

    This will return a list consisting of start vertex, edge, end vertex that make a relationship

    In case you need a path, then the following query would work

    SELECT * FROM cypher('graph', $$
    MATCH p = (n)-[e]->(m)
    RETURN p        
    $$) AS (result agtype);