skip to Main Content

From my understanding labels in apacheAGE are stored under the schema ag_labels, and also are separate tables that the vertices and edges are stored. Also every database object inside postgres is holding an oid. What is a way to see the oid’s of the different label relations inside a graph, or in general?

3

Answers


  1. You can run the following query to find the OID of labels table

    SELECT relname AS label_name, oid FROM pg_class WHERE relname = '<enter_label_name_here>';
    

    But there may be a situation where more than one graph can have the same labels. In that case, the above query returns multiple OIDs and we can not differentiate which OID belongs to which graph’s label. So, you need to join pg_class and pg_namespace in order to add a check for which graph you need to return the label’s OID.

    SELECT nsp.nspname AS graph_name, tbl.relname AS label_name, 
    tbl.oid AS oid
    FROM pg_namespace nsp
    JOIN pg_class tbl ON nsp.oid = tbl.relnamespace 
    WHERE nsp.nspname = '<enter_graph_name_here>' AND tbl.relname = '<enter_label_name_here>';
    

    Above you can replace tbl.relname = '_ag_label_vertex' or tbl.relname = '_ag_label_edge' to get the OID of vertices or edges table.

    Login or Signup to reply.
  2. To View all the vertexes and their Oids you can use the command

    SELECT * FROM "graph_name"._ag_label_vertex;
    

    This would return you 2 columns id and properties.
    Id is the Oid of a certain Vertex.

    And to View all the edges with their ID, Start Id and End ID you can use:

    SELECT * FROM "graph_name"._ag_label_edge;
    

    This would return you four columns: ID, Start Id, End ID and properties.

    Login or Signup to reply.
  3. In Apache AGE, it is possible to retrieve the object IDs (oids) for various database objects and label relations using the built-in functions. Below are some examples of how this can be achieved:

    To retrieve the oids for all tables in the current schema, execute the following query:

    SELECT oid, relname FROM pg_class WHERE relkind = 'r';
    

    This query selects the oid and table name for all regular tables in the pg_class system catalog.

    To retrieve the oids for all label relations in the current graph, execute the following query:

    SELECT oid, relname FROM ag_catalog.ag_labels;
    

    This query selects the oid and label name for all label relations in the ag_labels schema.

    To retrieve the oid for a specific label relation, execute the following query:

    SELECT oid FROM pg_class WHERE relname = 'my_label_relation';
    

    This query selects the oid for the label relation named ‘my_label_relation’.

    Note: the above examples assume that the user is connected to the PostgreSQL database where Apache AGE is running, and that the necessary privileges to query the system catalogs are available.

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