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.
-
What have you tried? What exactly was the result? Answer by updating the question - not as additional comment. Post all as text, not images. – Belayer Jul 05 '23 at 18:02
2 Answers
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
.
CREATE FUNCTION ag_catalog.agtype_build_map(VARIADIC "any")
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.

- 433
- 9
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 a variant
and use variant "any"
to handle multiple arguments with different types.

- 763
- 1
- 12