I am just wondering how to write a wrapper function in PostgreSQL (as of 12.x) for a heterogeneous
VARIADIC function such as jsonb_build_object
?
Most SQL examples of VARIADIC functions I can find are not heterogeneous. The VARIADIC part is essentially an array of elements of the same type. But I need to write a wrapper for jsonb_build_object
to do some post-processing. Here, the parameter types in the variadic part (key-value list) are not the same.
Currently, I write:
my_func(jsonb_build_object(k1, v1, k2, v2, ...))
But this boilerplate is becoming boring …
Best Answer
jsonb_build_object()
takesVARIADIC "any"
as input. The pseudo-type"any"
is a placeholder for any input type. Currently, that only works for a C function. The manual:There is no one-to-one translation for an implementation with another procedural language. There may be workarounds, depending on your exact objective.