I changed the create_vlabel
function so that the new vertex label inherits from an existing label. Here is the block of code that allows this inheriting functionality:
// checking if user has provided the parent's name list.
if (!PG_ARGISNULL(2)) {
// Get the content from the third argument
array = PG_GETARG_ARRAYTYPE_P(2);
// Deconstruct the ArrayType to NAMEOID.
deconstruct_array(array, NAMEOID, -1, false, 'i', &elements, &parent_nulls, &nelements);
// Check for each parent in the list.
for (int i = 0; i < nelements; i++) {
parent_name_str = DatumGetCString(elements[i]);
// Check if parent label does not exist
if (!label_exists(parent_name_str, graph_oid)) {
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("parent label \"%s\" does not exist.", parent_name_str)));
}
rv = get_label_range_var(graph, graph_oid, parent_name_str);
lappend(parent, rv);
elog(NOTICE, "VLabel %s will inherit from %s", label_name_str, parent_name_str);
}
}
create_label(graph, label, LABEL_TYPE_VERTEX, parent);
You can see the full code here
First I create a vertex label as :
SELECT * FROM ag_catalog.create_vlabel('demo', 'Person');
NOTICE: VLabel "Person" has been created
create_vlabel
---------------
(1 row)
And then I try to create a new vertex label that inherits from this previous one :
SELECT * FROM ag_catalog.create_vlabel('demo', 'Programmer', ARRAY['Person']);
But then I get this error :
NOTICE: VLabel Programmer will inherit from Person
NOTICE: merging multiple inherited definitions of column "id"
NOTICE: merging multiple inherited definitions of column "properties"
ERROR: column "id" inherits conflicting default values
HINT: To resolve the conflict, specify a default explicitly.
How can I solve the error above?