1

I am working on Apache AGE, and I want all the child labels of a given Parent Label.
Example:
I have an edge named PARENT, and GRANDCHILD, CHILD inherits this PARENT. I want all the edges which inherit PARENT from the PostgreSQL table. Given I have the OID of PARENT edge Label available. I want to get all the OIDs of the child labels.

What I have done so FAR:

SELECT * FROM create_elabel('test', 'PARENT'); -- Created an edge Label named PARENT
SELECT * FROM create_elabel('test', 'CHILD', ARRAY['PARENT']); -- Created an edge Label named CHILD, Inherits PARENT
SELECT * FROM create_elabel('test', 'GRANDCHILD', ARRAY['PARENT']); -- Created an edge Label named GRANDCHILD, Inherits PARENT

Now In code I want the OIDs of CHILD and GRANDCHILD when I look for children of PARENT.
Which PostgreSQL function would allow me to do that?

Ken White
  • 123,280
  • 14
  • 225
  • 444
  • Hey Muhammad your questions needs some explanation as it is related to in-development branch/feature as the current signature of **create_elabel** accepts the first two arguments from your query example, so, please don't forget to mention that on your question because in the release or the master branch those second and third queries throws that: HINT: No function matches the given name and argument types. You might need to add explicit type casts. – Mohamed Mokhtar - rrrokhtar Apr 01 '23 at 20:22

1 Answers1

1

You can use the find_inheritance_children function, which is going to return a list of the child label tables OID. Also, it is necessary to check before if the current label has child edges, using the has_subclass function. The has_subclass function receives a Relation type argument and will return a boolean (True if there exists a child edge or False if it doesn't). Assuming that you already have the OID of the parent label, the code must be something like:

// add this to use the functions.
#include "catalog/pg_inherits.h"

List *child_edges_oid;

// verify if the current edge has child edges
if (has_subclass(edge_label_table_oid))
{

    // get the edge's child labels OIDs 
    child_edges_oid = find_inheritance_children(edge_label_table_oid, NoLock);
}
Matheus Farias
  • 716
  • 1
  • 10