Search code examples
apache-age

How should I call the builtin Apache AGE function _agtype_build_vertex from psql terminal?


From the psql terminal, I'm trying to use an Apache AGE builtin function with the following signature:

Datum _agtype_build_vertex(PG_FUNCTION_ARGS)

the function is located here: https://github.com/apache/age/blob/a84c0392ffcfe63ecbc70ca4b45f1f0c3de28f7d/src/backend/utils/adt/agtype.c#L2167

but I wasn't able to call it with the proper arguments.

I tried the following commands on psql terminal (the error messages are shown below the commands):

test=# select _agtype_build_vertex(1,"vertex", "{}");
-- "ERROR:  column "vertex" does not exist at character 22"

test=# SELECT agtype_build_vertex(1,"_ag_label_vertex","{}");
ERROR:  column "_ag_label_vertex" does not exist at character 30

test=# SELECT * FROM agtype_build_vertex(1,"_ag_label_vertex","{}");
ERROR:  column "_ag_label_vertex" does not exist at character 37

What would be the proper way to call this function?


Solution

  • These are some of the correct ways of calling the function from psql terminal and also age-viewer.

    --Basic Vertex Creation
    SELECT _agtype_build_vertex('1'::graphid, $$label_name$$, agtype_build_map());
    SELECT _agtype_build_vertex('1'::graphid, $$label$$, agtype_build_map('id', 2));
    
    --Null properties
    SELECT _agtype_build_vertex('1'::graphid, $$label_name$$, NULL);
    

    This SQL script has many more examples of calling _agtype_build_vertex and other functions.