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?
Question posted in PostgreSQL
The official documentation can be found here.
The official documentation can be found here.
2
Answers
You are correct, but you also need to change the function signature in the "age–1.2.0.sql" file, updating the arguments:
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 usePG_GETARG_INT32(index_of_the_argument)
, for strings,PG_GETARG_CSTRING(n)
, and so on.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.