Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AGE Graph is actually stored as a postgreSQL Table, Right ? How to retrieve that Table (not Graph)?

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

like image 220
Mohayu Din Avatar asked Dec 07 '25 06:12

Mohayu Din


2 Answers

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;
like image 185
Matheus Farias Avatar answered Dec 09 '25 20:12

Matheus Farias


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.

like image 45
Rafsun Masud Avatar answered Dec 09 '25 20:12

Rafsun Masud