Search code examples
postgresqlcypherapache-age

How can I create a table using a query on a graph database such that the node properties become the fields in the table?


I am using AGE and I want to create a table from the data stored in the nodes. The nodes in my graph database have properties that store data about the node. I need to write a query that returns the node data in a tabular format, with each property becoming a field in the table.

For example, if I have a node with properties name, age, and city, I want my query to return a table with three columns, name, age, and city, and one row for each node.


Solution

  • The following query will return properties in a tabular format:

    SELECT * 
    FROM cypher('graph',
    $$
        MATCH (n)
        RETURN n.name, n.age, n.city
    $$
    ) as (name agtype, age agtype, city agtype);