skip to Main Content

I am connected to a database named ‘testdb’ using the PSQL utility with the ‘age’ extension loaded, How can I retrieve all the details(vertexes, relationship) of all graphs available in a database and also the number of graphs present in apache age?

I know using the query:

SELECT * FROM ag_catalog.ag_graph;

we can retrieve all the graph names but I need to access all vertex and relationships in each graph as well.

3

Answers


  1. Try using these SQL statements:

    SELECT * FROM age_graph.vertex; To get the vertices of the graph.

    SELECT * FROM age_graph.edge; To get the edges.

    I hope this was of help.

    Login or Signup to reply.
  2. For a given graph, you can extract vertices and edges using 2 cypher queries.

    For Vertices

    SELECT * FROM cypher('graph_name', $$ MATCH (n) RETURN n $$) as (v agtype);
    

    For Edges

    SELECT * FROM cypher('graph_name', $$ MATCH ()-[r]->() RETURN r $$) as (e agtype);
    

    ELSE you can execute a single cypher query with multiple returns to get the desired output.

    SELECT * FROM cypher('graph_name', $$ MATCH (n), ()-[r]->() RETURN n, r $$) as (v agtype, e agtype);
    

    You can try using the python driver or any other AGE driver to execute this easily. You can simply fetch all the graph names using :

    SELECT * FROM ag_catalog.ag_graph;
    

    and then execute above cypher queries iteratively over different graph names.

    Login or Signup to reply.
  3. You could use SELECT * FROM ag_catalog.ag_label to view information about the vertices and edges in all your graphs, this should output something like this:

           name       | graph | id | kind |         relation          |        seq_name
    ------------------+-------+----+------+---------------------------+-------------------------
     _ag_label_vertex | 16943 |  1 | v    | demo._ag_label_vertex     | _ag_label_vertex_id_seq
     _ag_label_edge   | 16943 |  2 | e    | demo._ag_label_edge       | _ag_label_edge_id_seq
     node             | 16943 |  3 | v    | demo.node                 | node_id_seq
     edge             | 16943 |  4 | e    | demo.edge                 | edge_id_seq
     _ag_label_vertex | 24579 |  1 | v    | my_graph._ag_label_vertex | _ag_label_vertex_id_seq
     _ag_label_edge   | 24579 |  2 | e    | my_graph._ag_label_edge   | _ag_label_edge_id_seq
     Person           | 24579 |  3 | v    | my_graph."Person"         | Person_id_seq
     Friends          | 24579 |  4 | e    | my_graph."Friends"        | Friends_id_seq
     Collegues        | 24579 |  5 | e    | my_graph."Collegues"      | Collegues_id_seq
    (9 rows)
    

    As you can see, the above contains the information of all the nodes and edges of all your graphs. You can see that the vertices are labeled ‘v’ and the edges are labeled ‘e’.
    So from this you could run a query like;

    SELECT * FROM my_graph."Friends";
    

    And you will get the details of the relationship ‘Friends’;

            id        |    start_id     |     end_id      | properties
    ------------------+-----------------+-----------------+------------
     1125899906842625 | 844424930131969 | 844424930131970 | {}
    (1 row)
    

    Overall I think running SELECT * FROM ag_label; will really give you a view of all the nodes and egdes in all your graphs.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search