Reputation: 129
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?
Upvotes: 1
Views: 106
Reputation: 715
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);
}
Upvotes: 1