2

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

Mohayu Din
  • 433
  • 9
  • *Apache AGE is actually a Postgres table right?* **Absolutely not**. [Apache AGE®](https://age.incubator.apache.org/) for starters. – Belayer Feb 24 '23 at 08:51
  • Then why they say that you can perform both SQL and Cypher on the AGE graphs. Graph must be stored as a table if you want to perform SQL on it. Right? – Mohayu Din Feb 24 '23 at 09:22
  • Does `select * from graph1.graph1` work? –  Feb 24 '23 at 10:02
  • No it does not work – Mohayu Din Feb 24 '23 at 14:46
  • Sorry, we [can't accept images of code, data or errors](https://meta.stackoverflow.com/a/285557). Post those as *text*, so that we can try to reproduce the problem without having to re-type everything, and your question can be properly indexed or read by screen readers. – Martijn Pieters Mar 16 '23 at 11:19

2 Answers2

3

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;
Matheus Farias
  • 716
  • 1
  • 10
1

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.