AGE’s functions can be found in the age–1.3.0.sql file. Although there are no examples of function overloading, is there any possibility to create multiple functions with the same name but with different parameters for AGE? If yes, then how? If not, then why? Thanks in advance.
Question posted in PostgreSQL
The official documentation can be found here.
The official documentation can be found here.
2
Answers
It’s possible to create multiple functions with the same name, you can see some examples here. However, remember that when overloading C-language functions, you need to the use different C names for each function in the family of overloaded functions. Read the documentation provided to learn more.
Another alternative if you need to process different argument types is using
"any"
as the parameter for your function and then handle the type in the function implementation in C. You can add avariant
and usevariant "any"
to handle multiple arguments with different types.Rather than creating two functions with the same name, it is preferred to use a single function with varying numbers of arguments of different types. This behavior is found in many AGE functions, such as
agtype_build_map
.In this case, you create a function with a VARIADIC "ANY" datatype, where "variadic" indicates a variable number of parameters, and "any" indicates that the parameters can be of any datatype.