I am trying to build a documentation system for my database and I would like to include the source of my functions and triggers.
I managed to find all of the metadata on
Use the function pg_get_functiondef() to get the complete function definition:
SELECT pg_get_functiondef('my_schema.my_func(int)'::regprocedure)
The cast to the object identifier regprocedure is the simplest way to get the oid
of your function, which you feed to the above function.
The manual on pg_catalog.pg_proc:
For compiled functions, both built-in and dynamically loaded,
prosrc
contains the function's C-language name (link symbol). For all other currently-known language types,prosrc
contains the function's source text.
To retrieve the function body only:
SELECT prosrc
FROM pg_proc
WHERE oid = 'my_schema.my_func(int)'::regprocedure;