skip to Main Content

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.

2

Answers


  1. From Reference: https://age.apache.org/age-manual/master/intro/types.html#graphid:

    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.

    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.

    Login or Signup to reply.
  2. 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.

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