1

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?

Matheus Farias
  • 716
  • 1
  • 10

1 Answers1

0

To solve this problem, first I had to create a new variable in the code to check if the function is going to inherit from any additional labels. I called this function is_inheriting.

Additionally, I also added this variable as an argument to the create_vlabel , create_table_for_label and create_label functions.

Inside the create_table_for_label function is where the default values for the label are created. I altered an if statement so that it also checks if the label to be created inherits from the labels from the array:

    /*
     * When a new table has parents, do not create a column definition list.
     * Use the parents' column definition list instead, via Postgres'
     * inheritance system.
     */
    if (list_length(parents) != 0 && is_inheriting == NO_INHERITANCE)
        create_stmt->tableElts = NIL;
    else if (label_type == LABEL_TYPE_EDGE)
        create_stmt->tableElts = create_edge_table_elements(
            graph_name, label_name, schema_name, rel_name, seq_name);
    else if (label_type == LABEL_TYPE_VERTEX)
        create_stmt->tableElts = create_vertex_table_elements(
            graph_name, label_name, schema_name, rel_name, seq_name);
    else
        ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR),
                        errmsg("undefined label type \'%c\'", label_type)));
Matheus Farias
  • 716
  • 1
  • 10