AGE图实际上存储为PostgreSQL表,是吗?如何检索该表(而不是图)?

huangapple go评论61阅读模式
英文:

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

问题

创建 PostgreSQL 表时,我们可以使用以下查询来查看其行和列:SELECT * FROM <table_name>。当我们创建一个 AGE 图时,实际上它也是一个 PostgreSQL 表。要检索原始图的表数据,您可以运行以下查询:

SELECT * FROM <table_name>;

请注意,上述查询中的 "<table_name>" 应替换为实际的表名称。

英文:

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.

AGE图实际上存储为PostgreSQL表,是吗?如何检索该表(而不是图)?

答案1

得分: 3

创建图时,它的名称和命名空间将存储在ag_catalog.ag_graph表中。在PostgreSQL中,命名空间是一个命名模式,其中包含数据库对象的集合,如表、视图、函数、序列和类型。在PostgreSQL中,命名空间也被称为模式。

当您调用SELECT * FROM create_graph('ag_graph')时,它将添加它的名称和命名空间到我提到的表中,并在该命名空间内创建一些标准表:_ag_label_vertex_ag_label_edge。这些将成为您创建的任何新顶点或边标签的父表。

因此,如果您想查看图中的所有顶点或边,您可以执行以下查询:

SELECT * FROM "ag_graph"._ag_label_vertex;
SELECT * FROM "ag_graph"._ag_label_edge;
英文:

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(&#39;ag_graph&#39;) 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 &quot;ag_graph&quot;._ag_label_vertex;
SELECT * FROM &quot;ag_graph&quot;._ag_label_edge;

答案2

得分: 1

图形以模式(Postgres中的命名空间)的形式存储。图中的每个标签都有自己的表。顶点和边存储为它们各自标签的表中的一行。每行都具有id和属性属性。边行包含两个额外的id属性,用于引用端点顶点。

如果您想选择图中标记为Professor的所有顶点,您可以这样写:

SELECT * FROM mygraph."Professor";

但我建议在完全了解这些表的结构之前不要运行任何UPDATE命令。例如,更改顶点的id实际上可能会'移除'与其边的连接,因为顶点表和边表之间没有外键约束。

我在这篇文章中解释了AGE如何使用表来表示图形 这里。我不想重复详细信息。如果您感兴趣,请查看它。

英文:

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.&quot;Professor&quot;;

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.

huangapple
  • 本文由 发表于 2023年2月24日 16:42:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/75554331.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定