Home > Enterprise >  Can we get graphID(Oid) of a graph on postgresql terminal
Can we get graphID(Oid) of a graph on postgresql terminal

Time:01-31

I have created a graph called 'cyc_graph', Now I'm testing to see if I can insert some vertices in this graph using the agtype_build_map function, but this function requires graphID as a parameter. So How can I get the graphID of a graph already created from PostgreSQL terminal?

I tried something like this

SELECT 'cyc_graph.vtxs'::regclass::oid;

But this gives Oid of vtxs table. (vtxs is label name for vertices). I understand that cyc_graph is a schema name. So I don't know how can I get graphID/Oid of a schema name.

CodePudding user response:

What is GraphID?
Simple entities are assigned a unique graphid. A graphid is a unique composition of the entity’s label id and a unique sequence assigned to each label. Note that there will be overlap in ids when comparing entities from different graphs.

Reference: https://age.apache.org/age-manual/master/intro/types.html

test=# LOAD 'age';
LOAD
test=# SET search_path = ag_catalog, "$user", public;
SET
test=# SELECT * FROM cypher('graph', $$
MATCH (v)
RETURN v
$$) as (v agtype);
                                                     v
------------------------------------------------------------------------------------------------------------
 {"id": 844424930131969, "label": "Person", "properties": {"name": "John"}}::vertex
 {"id": 844424930131970, "label": "Person", "properties": {"name": "Jeff"}}::vertex
 {"id": 844424930131971, "label": "Person", "properties": {"name": "Joan"}}::vertex
 {"id": 844424930131972, "label": "Person", "properties": {"name": "Bill"}}::vertex
 {"id": 844424930131973, "label": "Person", "properties": {"name": "Andres", "title": "Developer"}}::vertex
(5 rows)

Here the id is actually GraphID.

CodePudding user response:

Inside the terminal, after loading AGE extension and setting search_path, use the command:

SELECT oid, name 
FROM ag_graph;

It will output something like this:

  oid   |       name
-------- -------------------
  72884 | graph1
 353258 | graph2
 353348 | graph3
(3 rows)

The column oid is the Oid of the graphs.

But maybe you want to do it from the source code?

Call the function search_graph_name_cache(char* graph_name); (located here)

It will return a pointer to a struct defined as graph_cache_data, which has the Oid of the graph.

  • Related