skip to Main Content

I was looking inside the create_vlabel function and noted that to get the graph_name and label_name it is used graph_name = PG_GETARG_NAME(0) and label_name = PG_GETARG_NAME(1). Since these two variables are also passed as parameters, I was thinking that, if I wanted to add one more parameter to this function, then I would need to use PG_GETARG_NAME(2) to get this parameter and use it in the function’s logic. Is my assumption correct or do I need to do more tweaks to do this?

2

Answers


  1. You are correct, but you also need to change the function signature in the "age–1.2.0.sql" file, updating the arguments:

    CREATE FUNCTION ag_catalog.create_vlabel(graph_name name, label_name name, type new_argument)
        RETURNS void
        LANGUAGE c
    AS 'MODULE_PATHNAME';
    

    Note that all arguments come as a "Datum" struct, and PG_GETARG_NAME automatically converts it to a "Name" struct. If you need an argument as int32, for example, you should use PG_GETARG_INT32(index_of_the_argument), for strings, PG_GETARG_CSTRING(n), and so on.

    Login or Signup to reply.
  2. The answers given by Fahad Zaheer and Marco Souza are correct, but you can also create a Variadic function, with which you could have n number of arguments but one drawback is that you would have to check the type yourself. You can find more information here. You can also check many Apache Age functions made this way e.g agtype_to_int2.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search