skip to Main Content

When we create a postgreSQL Table, we are able to see its rows and cols with SELECT * FROM <table_name>. When we create an AGE Graph, it is also actually a postgreSQL Table. What query should I run to retrieve the original graph’s Table data.

enter image description here

2

Answers


  1. When you create a graph it’s name and namespace are going to be stored under ag_catalog.ag_graph table. In PostgreSQL, a namespace is a named schema that contains a collection of database objects, such as tables, views, functions, sequences, and types. A namespace is also known as a schema in PostgreSQL.

    When you call SELECT * FROM create_graph('ag_graph') it is going to add it’s name and namespace to the table that I mentioned, and also create some standard tables within this namespace: _ag_label_vertex and _ag_label_edge. These will be the parent tables of any new vertex or edge label you create.

    So then, if you want to see all the vertices or edges in your graph, you can execute the following queries:

    SELECT * FROM "ag_graph"._ag_label_vertex;
    SELECT * FROM "ag_graph"._ag_label_edge;
    
    Login or Signup to reply.
  2. Graphs are stored as schemas (namespace in Postgres). Each label in a graph, has its own table. Vertices and edges are stored as a row in their respective label’s table. Each row has id and properties attribute in common. An edge row contains two additional id attributes to refer to the endpoint vertices.

    If you want to SELECT all vertices labelled Professor in the graph mygraph, you would write this:

    SELECT * FROM mygraph."Professor";
    

    But, I would recommend not to run any UPDATE command on these tables without fully understanding how these tables are structured. For example, changing an id of a vertex can actually ‘remove’ connection with its edges, because there is no foreign key constraint between vertex tables and edge tables.

    I explained how AGE uses tables to represent graph in this article here. I do not want to repeat the details. If you are interested, please check it out.

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